[Tutor] code works in windows command but not ubuntu terminal

Peter Otten __peter__ at web.de
Fri Jan 24 10:31:10 CET 2014


Tobias Quezada wrote:

> hello community,i am a newbie to python and program in general.
> the script below works in python 2.7.3 on windows but not in the python
> 2.7.3 ubuntu terminal.
> 
>>>>fp=open("prez.dat","r")>>>x=fp.read>>>(print(x)***i used fp for file
>>>>pointer.I am using windows 7 and it works but on ubuntu 12.04 LTS i get
>>>>this syntax error:
> Traceback (most recent call last):  File "<stdin>", line 1, in
> <module>IOError: [Errno 2] No such file or directory: 'prez.dat'
 
That was probably

> fp=open("prez.dat","r")
> x=fp.read
> print(x)


> i used fp for file pointer.I am using windows 7 and it works but on ubuntu
> 12.04 LTS i get this syntax error:

> Traceback (most recent call last):  File "<stdin>", line 1, in
> <module>IOError: [Errno 2] No such file or directory: 'prez.dat'
> Any thoughts?Thanx

Please reread the error message. This is not a SyntaxError. Python is trying 
to tell you that a file called "prez.dat" doesn't exist in the current 
working directory. However, once you create the file (or provide the 
complete path if the file exists but is located in another directory) you 
will run into the next problem:

> x=fp.read

This will bind x to the fp.read method. To call the method the parentheses 
are mandatory:

x = fp.read()



More information about the Tutor mailing list