简体   繁体   中英

Python DictWriter: OSError: [Errno 22] Invalid argument: '\u202aC:Users\\...\\Desktop\\file.csv'

I know this has been asked and answered a couple of times. Still, the solutions posted so far do not fix my problem. I'm getting this error code when trying to open a csv-file with Python DictWriter.

I tried at least the following variations so far:

with open(r"‪C:/Users/.../Desktop/file.csv", 'w') as xfile:
with open("‪C:\\\\Users\\...\\Desktop\\file.csv", 'w') as xfile:
with open(r"‪C:\Users\...\Desktop\file.csv", 'w') as xfile:

Quotes requested by stackoverflow. I also used append method instead of write with no effect. The three dorts are a placeholder, the path is complete and correct.

So what could be the problem here? Any help would be much appreciated! Regards Thomas

From the comments, the solution was to delete the invisible control character U+202A (Left-to-Right Embedding) at the start of the path.

This blog post from Raymond Chen provides one possible explanation for this character turning up at the start of a Windows file path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM