Use and usefulness of the as syntax

Mel Wilson mwilson at the-wire.com
Sat Nov 12 08:59:40 EST 2011


candide wrote:
> First, could you confirm the following syntax
>> import foo as f
>> equivalent to
>> import foo
> f = foo
>>>> Now, I was wondering about the usefulness in everyday programming of 
the
> as syntax within an import statement. [ ... ]

It gives you an out in a case like
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> os = 5 # number of 'o's
>>> import os as opsys
>>> os
5
>>> opsys
<module 'os' from '/usr/lib/python2.6/os.pyc'>
(This is an instance of what arnaud mentioned.)
	Mel.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /