[Tutor] Problem in open function

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon Mar 31 17:18:02 2003


On Mon, 31 Mar 2003, antonmuhin at rambler.ru wrote:

> sc> how i can use built in open() functions when i have
> sc> imported os module which also have open() system call.
>
> sc> the code allows me to use one only why?

> 1. Use file instead (open even seems to be depricated now).
> 2. If you import with 'import os', then os.open should work, but it
> seems that you imorted it with 'from os import open'. In this case you
> migth want to save the old functiuon:
>
>   old_open = open
>   from os import open
>   old_open(...) # standard open
>   open(...) # os.open


Even so, it's probably a good idea to avoid using 'from os import open',
as lots of folks probably expect open() to stand for the standard
"builtin" open function.


Sudhir, it does sounds like you're using something like 'from os import
*'.  The 'from' statement's meant to plunk the contents of a module
directly into the global namespace for convenience sake, but is
problematic since it plunks the contents of a module directly into the
global namespace.  *grin*

Doing something like 'from os import *' ends up overwriting some important
builtin functions like open() so that they're not easily accessible
anymore.  Can you check to see if you can find that 'from os import *' in
your code?

The Python Tutorial does have a section on 'Importing * From a a Package';
it might be useful for you:

    http://www.python.org/doc/tut/node8.html#SECTION008410000000000000000


Good luck!