Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15621

Re: Use and usefulness of the as syntax

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!txtfeed1.tudelft.nl!tudelft.nl!txtfeed2.tudelft.nl!amsnews11.chello.com!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.018
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'situation.': 0.05; 'suppose': 0.05; 'forcing': 0.07; 'foo': 0.09; 'syntax': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:syntax': 0.16; 'wrote:': 0.18; 'received:209.85.210.174': 0.18; 'received:mail-iy0-f174.google.com': 0.18; 'header:In-Reply- To:1': 0.23; 'variable': 0.24; 'loaded': 0.25; 'separate': 0.28; 'sat,': 0.28; 'import': 0.28; 'around.': 0.28; 'bound': 0.28; 'convention': 0.28; 'importing': 0.28; 'message- id:@mail.gmail.com': 0.29; 'closer': 0.30; 'equivalent': 0.30; 'nov': 0.31; 'pm,': 0.31; 'to:addr:python-list': 0.32; 'done': 0.33; 'something': 0.36; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'option': 0.38; "it's": 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.40; '2011': 0.62; 'power,': 0.67; 'yourself': 0.68; '10:56': 0.84; 'candide': 0.84; 'different.': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=fSGBipvljr8rXRa3rMgooSXuK8jBnhQ1xiEjWSi8HW4=; b=ka+JLi6zIgscDVdcmh0QaaK3373uhIfay96GjtCsOLbYnS72OcooS0cxc4XZSkHY3I it201nsjaku9uWNY1xC06Z7DU5z3OoUBHvG8jgnjoRXdEUo5jPrrJ81OWY/xTU4LS/lw QQqBspKC1YiSlDcdKVvw93mZVye1df7lItN6A=
MIME-Version 1.0
In-Reply-To <4ebe5ee6$0$25872$426a74cc@news.free.fr>
References <4ebe5ee6$0$25872$426a74cc@news.free.fr>
Date Sat, 12 Nov 2011 23:27:56 +1100
Subject Re: Use and usefulness of the as syntax
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2668.1321100879.27778.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1321100879 news.xs4all.nl 6903 [2001:888:2000:d::a6]:57921
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:15621

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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