Python Forum

Full Version: Can't write to file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

What am I doing wrong here?

test_file = open("C:Users/Mark/Desktop/test.csv",mode="w")
for i in range(11):
    print(i, file=test_file)
test_file.close()
I'm getting FileNotFoundError: [Errno 2] No such file or directory: 'C:Users/Mark/Desktop/test.csv' .
I don't have a windows machine to test right now, but shouldn't there be a slash between the C: and the Users?
(Sep-24-2021, 03:37 PM)bowlofred Wrote: [ -> ]I don't have a windows machine to test right now, but shouldn't there be a slash between the C: and the Users?

Bingo. Thanks so much!

Mark