confusion about opening files

Mark McEahern marklists at
Mon Sep 23 23:02:38 EDT 2002

> O. K. Now I am confused.  I thought that when I imported the os module, i
> would have to call its functions like this:    Why am I 
> just using the function name?

You are assuming open ==  Not so.  Watch...


$ python
Python 2.2.1 (#1, Jun 25 2002, 10:55:46)
[GCC 2.95.3-5 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print open.__doc__
file(name[, mode[, buffering]]) -> file object

Open a file.  The mode can be 'r', 'w' or 'a' for reading (default),
writing or appending.  The file will be created if it doesn't exist
when opened for writing or appending; it will be truncated when
opened for writing.  Add a 'b' to the mode for binary files.
Add a '+' to the mode to allow simultaneous reading and writing.
If the buffering argument is given, 0 means unbuffered, 1 means line
buffered, and larger numbers specify the buffer size.
Note:  open() is an alias for file().

>>> import os
>>> print
open(filename, flag [, mode=0777]) -> fd
Open a file (for low level IO).
>>> open ==



// m

More information about the Python-list mailing list