[Tutor] Confusion regarding the 'from' statement

David Rock david at graniteweb.com
Tue Aug 14 20:43:59 CEST 2012


* Mazhar Hussain <yam.matt at gmail.com> [2012-08-14 23:24]:
> the module object with the del statement. However what happens if I
> try to import a name using 'from' that references a name in the
> imported module that itself is not imported. Consider the following
> example,here there are two modules mod1.py and mod2.py,
> 
> #mod1.py
> from mod2 import test
> test('mod1.py')
> 
> #mod2.py
> def countLines(name):
>     print len(open(name).readlines())
> 
> def countChars(name):
>     print len(open(name).read())
> 
> def test(name):
>     print 'loading...'
>     countLines(name)
>     countChars(name)
>     print '-'*10

Loosely speaking, it does import the other methods.  In order to
successfully import test(), it has to resolve countLines() and
countChars().  They won't be directly accessible, as they don't exist
in the namespace, but test() knows about them.  You are reading too much
into the comment that the module is "deleted".

-- 
David Rock
david at graniteweb.com


More information about the Tutor mailing list