Re: indirect import of standard module

2006-04-19 Thread Fredrik Lundh
BartlebyScrivener wrote: > >> More accurately, it *does* import it twice, into two separate > >> namespaces; > > If it's in two different namespaces, how can they have the same id > number? they're mixing up the terminology. each loaded module has exactly one namespace, no matter how many times

Re: indirect import of standard module

2006-04-18 Thread Ben Finney
"BartlebyScrivener" <[EMAIL PROTECTED]> writes: > >> More accurately, it *does* import it twice, into two separate > >> namespaces; > > If it's in two different namespaces, how can they have the same id > number? That "two different namespaces" might be a bit inaccurate. There is only one objec

Re: indirect import of standard module

2006-04-18 Thread BartlebyScrivener
Thank you for the elucidation. I'm just getting into Classes, but I wanted to get modules down first. Much appreciated. rick -- http://mail.python.org/mailman/listinfo/python-list

Re: indirect import of standard module

2006-04-18 Thread alisonken1
Although 'namespace' may be a misnomer, module interfaces are 'exposed' to the module that imports it - it's not imported a second time into the new 'namespace'. The confusion comes about thinking that modules and classes are related. When a module is first imported, an instance is created for th

Re: indirect import of standard module

2006-04-18 Thread BartlebyScrivener
>> More accurately, it *does* import it twice, into two separate >> namespaces; If it's in two different namespaces, how can they have the same id number? rick -- http://mail.python.org/mailman/listinfo/python-list

Re: indirect import of standard module

2006-04-18 Thread alisonken1
Actually, it does not "execute the code only the first time", more accurately, it "initializes the code only the first time". But you are correct, it exposes the os.* module into the current namespace so you don't have to go to convoluted lengths to get to it. -- http://mail.python.org/mailman/l

Re: indirect import of standard module

2006-04-18 Thread Ben Finney
"alisonken1" <[EMAIL PROTECTED]> writes: > Unless you override some of os.* functions in foo, you want to > import os into foo and bar separately. > > Python does not reimport the module a second time (create a second > instance of os) More accurately, it *does* import it twice, into two separat

Re: indirect import of standard module

2006-04-18 Thread BartlebyScrivener
You're right! When running bar.py, id(os) and id(foo.os) give the same number! Cool. I'll go read about INSTANCES and pointers. Thank you very much, rick -- http://mail.python.org/mailman/listinfo/python-list

Re: indirect import of standard module

2006-04-18 Thread alisonken1
Unless you override some of os.* functions in foo, you want to import os into foo and bar separately. Python does not reimport the module a second time (create a second instance of os), it only creates a pointer to the first instance that's loaded. -- http://mail.python.org/mailman/listinfo/pyth

indirect import of standard module

2006-04-18 Thread BartlebyScrivener
I know this must have been answered a hundred times, but I must be searching on the wrong terminology. Let's say I have a module foo.py that imports os. I make another script called bar.py that imports foo.py and now I want to use, say, os.walk in bar.py. Which is faster or more correct or whate