Question on lists

Christopher T King squirrel at WPI.EDU
Thu Jul 29 11:00:14 EDT 2004


On Thu, 29 Jul 2004, Alan G Isaac wrote:

> Newbie question:
> OK, this is great.  But I was not aware of this module,
> and I was working in my own sets.py.
> So how do I handle this namespace issue?
> I.e., how can I 'import sets' and get the Python module,
> when my own script is named sets.py?

The best way, of course, is to rename your script ;) it's never a good 
idea to give a script the same name as that of a module you plan to use.

If you absolutely must leave your script named sets.py, you can use the 
following trick to get to Python's sets.py:

 import sys
 sys.path.remove('')
 import sets

This removes the current directory from Python's search path.  Note you 
won't be able to access any modules in the current directory after that 
line, unless you do a "sys.path.insert(0,'')" first.




More information about the Python-list mailing list