Search code examples
pythonsaveshareddrive

Python Saving to Mapped Shared Drive Error


I'm attempting to save a file to a mapped network drive Z: & The error I'm getting is SyntaxError: 'EOL while scanning string lateral'. I've tried this code with a local drive with no issue. Any tips on referencing a mapped shared drive.

with open ('test.txt','r') as file:
    text = file.read()
    with open(' Z:\\example.job.com@SSL\site\more\specific\folder\files','w') as file:
        file.write(text)

Solution

  • Did you not escape the backslashes? try:

    directory = r"Z:\\example.job.com@SSL\site\more\specific\folder\files"
    with open ('test.txt','r') as file:
        text = file.read()
        with open(directory,'w') as file:
            file.write(text)