Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'motivated': 0.05; 'retrieved': 0.05; 'attribute': 0.07; 'foo': 0.09; 'namespace': 0.09; 'statement.': 0.09; 'cc:addr:python-list': 0.15; 'syntax': 0.15; '"from': 0.16; 'numpy': 0.16; 'subject:syntax': 0.16; 'to:addr:free.fr': 0.16; 'wrote:': 0.18; 'seems': 0.19; 'figure': 0.20; 'cc:no real name:2**0': 0.21; 'programming': 0.21; "doesn't": 0.23; 'header:In-Reply-To:1': 0.23; 'cc:2**0': 0.25; 'code': 0.25; 'math': 0.25; 'import': 0.28; 'bound': 0.28; 'cc:addr:python.org': 0.29; 'message-id:@mail.gmail.com': 0.29; 'second': 0.29; 'module': 0.30; 'equivalent': 0.30; 'wondering': 0.32; "isn't": 0.32; 'widespread': 0.34; 'modules': 0.35; 'received:209.85.161': 0.35; 'rather': 0.35; 'doing': 0.37; 'but': 0.37; 'two': 0.37; 'could': 0.38; 'received:google.com': 0.38; 'some': 0.38; 'received:209.85': 0.38; 'help': 0.39; 'why': 0.39; 'case': 0.39; 'subject:: ': 0.39; 'received:209': 0.40; 'within': 0.60; '2011': 0.62; 'here': 0.65; 'confirm': 0.69; 'candide': 0.84; 'need,': 0.91 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 :cc:content-type; bh=x46kQu76lGTTW1rl5BfAwJDmBmG2IPxppEZtkzcMA8U=; b=DCaqiyDaCWDPLWCsubNLNr1Y47QCcGekRi5klysWv2kH0MmawLO22HvvaTwrpECBXv sX3yr7eo5k/NjVmBaEVhuQyhrEmc6lrH6tdyLujxMzOnXGtlPYgo/CAr3UDvTxfagVye 42GVOfa/vkj+UqyFHP+kRpu7vCjBav+YdBA18= 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 12:29:26 +0000 Subject: Re: Use and usefulness of the as syntax From: Arnaud Delobelle To: candide Content-Type: text/plain; charset=UTF-8 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1321100968 news.xs4all.nl 6891 [2001:888:2000:d::a6]:58931 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15622 On 12 November 2011 11:56, 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. Here are some instances retrieved from > real code of such a syntax > > import numpy as np > > import math as _math > > import pickle as pickle > > > -- In the first case, the syntax is motivated by brevity need, isn't it ? Correct! > -- The second case seems to be rather widespread and causes math attribute > to be private but I don't figure out why this matters. This way math doesn't get bound in the global namespace when doing "from module import *" > -- In the last case, I can see no point Neither can I > So what is the pragmatics of the as syntax ? It can also help when you want to import two different modules with the same name. -- Arnaud