[Tutor] Help with file I/O.

Alan G alan.gauld at freenet.co.uk
Mon Aug 1 00:11:57 CEST 2005

> file = raw_input("File name please: ")
> f = file(file, "r")

The problem is you used 'file' as a name. But file() is the function 
to open a file. So in the second line you call your filename as 
if it was a function!

Try using 'filename' for your variable instead. It's never a good 
idea to use a python built-in name as a variable.

You could just use open() instead of file() of course but 
thats probably not such a good solution!


Alan G
Author of the Learn to Program web tutor

More information about the Tutor mailing list