conflict between my package and os standard module

Fred L. Drake, Jr. fdrake at acm.org
Tue Jan 18 13:11:24 EST 2000


Ben Wittner writes:
 > In my_proj/os.py I put the following line:
 > 
 > import os
 > 
 > Since my_proj is NOT on my PYTHONPATH, I thought that the line above
 > would cause the standard module os to be imported.

  The reasons it works the way it does have already been explained, so 
I won't repeat the explanation.
  I haven't seen anyone suggest doing the import of the "real" os
module like this, in my_proj/os.py:

os = __import__("os")

This isn't the prettiest, but it works and is about as clean as it
gets short of a "virtual" package that provides access to the real
things.  The only weirdnesses with __import__() are with dotted module 
names; see the chapter 2 of the Library Reference for more
information.


  -Fred

--
Fred L. Drake, Jr.	  <fdrake at acm.org>
Corporation for National Research Initiatives




More information about the Python-list mailing list