file open() problem

Joshua Macy amused at webamused.com
Fri Apr 28 04:43:03 EDT 2000


 That's the right syntax, and it works for me (admittedly, on Linux,
Win95, and WinNT, not Win98)


Python 1.5.2 (#1, Sep 17 1999, 20:15:36)  [GCC egcs-2.91.66
19990314/Linux (egcs- on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> f = open('file.txt', 'r')
Traceback (innermost last):
  File "<stdin>", line 1, in ?
IOError: [Errno 2] No such file or directory: 'file.txt'
>>> f = open('file.txt', 'w')
>>> f.write('Spam, Eggs, and Spam')
>>> f.close()
>>> f = open('file.txt', 'r')
>>> r = f.readlines()
>>> print r
['Spam, Eggs, and Spam']
>>> 


 Have you done anything that might have hidden the builtin "open" with a
different one?  Is this the first thing that you're doing at the >>>
prompt, or have you entered some "from blah import *" lines first?


  Joshua

ekw1 at my-deja.com wrote:
> 
> I am using python1.5.2 on windows98se.  all of the following gives me
> an error.
> 
> f = open('file.txt', 'r')
> f = open("file.txt", "r")
> f = open('c:/dir/file.txt', 'r')
> f = open('c:\dir\file.txt', 'r')
> f = open("c:/dir/file.txt", "r")
> f = open("c:\dir\file.txt", "r")
> f = open("c:\\dir\\file.txt", "r")
> 
> The error from the python shell for any of the above is:
> 
> Traceback (innermost last):
>   File "<pyshell#17>", line 1, in ?
>     f = open('file.txt', 'r')
> TypeError: illegal argument type for built-in operation
> 
> Can anyone help me?  Thanks.
> 
> ekw
> 
> Sent via Deja.com http://www.deja.com/
> Before you buy.



More information about the Python-list mailing list