problem opening a file on 2.2a1

Skip Montanaro skip at pobox.com
Mon Aug 20 14:47:09 EDT 2001


    Rajarshi> data = open('data.out','w')

    Rajarshi> works fine. But when I try it froma  script I get the error:

    Rajarshi> Traceback (most recent call last):
    Rajarshi>   File "./p.py", line 12, in ?
    Rajarshi>     data = open('data.out','w')
    Rajarshi> TypeError: an integer is required

I'd insert a print statement right before the call to open:

    print open

to see if it's really the open function you think it is.  Are you perhaps
executing something like

    from os import *

?  The posix module defines an open function with a different signature than
the builtin open function.  In particular, the second argument is a flags
argument that expects an integer.

Very few modules in the standard library (or other places) are designed to
be executed as "from module import *".  The types, Tkinter, and dumbdbm
modules comes to mind.  The os module is definitely not designed to imported
that way.

-- 
Skip Montanaro (skip at pobox.com)
http://www.mojam.com/
http://www.musi-cal.com/




More information about the Python-list mailing list