Jan-06-2022, 05:33 PM
(Jan-06-2022, 03:24 AM)sjcsvatt Wrote: with open(r"\\192.168.1.4\aaaa\" + file_name, 'w',encoding='utf-8') as wf:
For windows paths, I prefer to use forward slashes. They work just fine. You are trying to escape them via r-strings, but there's a subtlety. Because they were developed for regex escapes, they ignore backslashes at the end. Your first string has a backslash at the end that is either ignored or ends up escaping the quote.
>>> r"\\file" '\\\\file' >>> r"\\file\" File "<stdin>", line 1 r"\\file\" ^ SyntaxError: EOL while scanning string literalBetter is to use use pathlib or use forward slashes. Try instead:
with open("//192.168.1.4/aaaa/" + file_name, 'w',encoding='utf-8') as wf: