Admittedly, I am a novice; however, (I think) I did what the tutorial said (for the version I installed) and I can't get Python to read a file. Others have had problems with long file names or paths, but I kept mine short and sweet... so I thought.
The file itself contains one word on a single line.
The print('string') works, len('string') works...
Here's what I got, in IDLE and CMD, even before using the import statements included below:
Python 3.2.2 (default, Sep 4 2011, 09:07:29) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
import os, csv, urllib
f0txt = ()
f0txt = open("C:\try\in0.txt")
Traceback (most recent call last):
File "
<pyshell#4
>", line 1, inf0txt = open("C:\try\in0.txt")
IOError: [Errno 22] Invalid argument: 'C:\try\in0.txt'
\
is an escape character. Try open(r"C:\try\in0.txt")
or open("C:\\try\\in0.txt")
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With