Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #15621
| References | <4ebe5ee6$0$25872$426a74cc@news.free.fr> |
|---|---|
| Date | 2011-11-12 23:27 +1100 |
| Subject | Re: Use and usefulness of the as syntax |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2668.1321100879.27778.python-list@python.org> (permalink) |
On Sat, Nov 12, 2011 at 10:56 PM, candide <candide@free.invalid> wrote:
> import foo as f
>
> equivalent to
>
> import foo
> f = foo
>
Not quite, it's closer to:
import foo
f = foo
del foo
without the fiddling around. What the 'import... as' syntax gives is a
way to separate the thing loaded from the name bound to. Suppose
importing were done thus:
foo = import("foo.py")
Then you'd have a standard convention of always importing into a
variable of the same name (loose terminology, but you know what I
mean), with the option of importing as something completely different.
The "import... as" syntax gives the same power, without forcing you to
repeat yourself in the common situation.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Use and usefulness of the as syntax candide <candide@free.invalid> - 2011-11-12 12:56 +0100
Re: Use and usefulness of the as syntax Chris Angelico <rosuav@gmail.com> - 2011-11-12 23:27 +1100
Re: Use and usefulness of the as syntax Arnaud Delobelle <arnodel@gmail.com> - 2011-11-12 12:29 +0000
Re: Use and usefulness of the as syntax candide <candide@free.invalid> - 2011-11-17 16:48 +0100
Re: Use and usefulness of the as syntax alex23 <wuwei23@gmail.com> - 2011-11-17 18:38 -0800
Re: Use and usefulness of the as syntax Tim Chase <python.list@tim.thechases.com> - 2011-11-12 06:43 -0600
Re: Use and usefulness of the as syntax Rafael Durán Castañeda <rafadurancastaneda@gmail.com> - 2011-11-12 13:48 +0100
Re: Use and usefulness of the as syntax 0xfn <oleg.rimko@gmail.com> - 2011-11-13 00:55 -0800
Re: Use and usefulness of the as syntax Terry Reedy <tjreedy@udel.edu> - 2011-11-13 17:16 -0500
Re: Use and usefulness of the as syntax Tim Wintle <tim.wintle@teamrubber.com> - 2011-11-12 13:03 +0000
Re: Use and usefulness of the as syntax Mel Wilson <mwilson@the-wire.com> - 2011-11-12 08:59 -0500
Re: Use and usefulness of the as syntax candide <candide@free.invalid> - 2011-11-17 16:48 +0100
csiph-web