[Tutor] Difference between >>> import modulex and >>> from modulex import *?

hcohen2 hcohen2 at comcast.net
Sat Jan 3 20:43:30 EST 2004


Kirk Bailey wrote:

> ok, then let me ask:
> I wish to import the function bar from the module Fu. In it's 
> definition, it depends on another function in Fu (named janfu)I did 
> not specify in the
> "from foo import bar" statement. What comes about as a result of this?
>
> hcohen2 wrote:
>
>> Todd G. Gardner wrote:
>>
>>> Hello Everyone,
>>>
>>> I have some questions that I must have skipped the answers in the 
>>> tutorial.
>>> Pardon me if they are obvious.
>>>
>>> 1) What is the difference between ">>> import modulex" and ">>> from 
>>> modulex
>>> import *"?
>>>
>>> 2) What happens when the command reads ">>> from modulex import 
>>> something"?
>>>    2a) Is something a function that is imported from modulex?
>>>
>>> Thank in advance,
>>>
>>> Thank you,
>>>
>>> Todd
>>>
>>>
>>> _______________________________________________
>>> Tutor maillist  -  Tutor at python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>>  
>>>
>> I think this will essentially repeat what was said, but perhaps more 
>> concisely:
>>
>> In the first case you have imported every built in function of that 
>> module.
>>
>> In the second you have only imported the specificly named function 
>> 'from' that module.
>>
>> In the first case you are free to execute every built in function 
>> from that module if you needed them.  In the second you are 
>> restricted to only the function you had imported.
>>
>>
>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
I would not assert this does not happen, but if it does there were some 
bad design decisions that would allowed this to occur.

I would have expected functions that were so dependent would be within a 
single module where one would: from modulex import sub_module ...  The 
specific function would not be named but would be readily executable 
because its dependency would be present.  This definitely does not seem 
to be the way I have seen it in my limited experience.

I would caution you that I am too new to Python to pretend to be an 
authority even on its basic features at this time.  Perhaps this will 
attract a much more knowledgeable comment from someone following this 
thread.




More information about the Tutor mailing list