write file to a server

Chris Angelico rosuav at gmail.com
Wed Jan 28 09:12:15 EST 2015


On Thu, Jan 29, 2015 at 12:38 AM, MRAB <python at mrabarnett.plus.com> wrote:
> On 2015-01-28 13:22, luca72 wrote:
>>
>> Hello i'm under windows, i have to write a file from my computer to a
>> local server like taht "\\DOCUMENTALE\my_folder\".
>> How i have to proceed ?
>>
> That's a path to a folder that just happens to be on another computer on
> your network. Treat it the same way you would for a 'local' folder,
> eg "C:\my_folder".

And if you've done that and it isn't working, one likely cause is that
Windows uses backslashes in path names, but Python string literals
treat backslashes specially. Use a raw string literal:

path = r"\\DOCUMENTALE\my_folder\some_file_name"
with open(path, "wb") as f:
    ... write to file ...

If you have other problems, the best thing to do is to post your code
and the exact output it produces, especially if that's a traceback.
Those are incredibly helpful.

ChrisA



More information about the Python-list mailing list