Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!amsnews11.chello.com!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'retrieved': 0.05; 'importerror:': 0.07; 'first:': 0.09; 'foo': 0.09; 'statement.': 0.09; 'tkinter': 0.09; 'cc:addr:python-list': 0.15; 'syntax': 0.15; '"import': 0.16; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'guessing': 0.16; 'message-id:@tim.thechases.com': 0.16; 'namespace.': 0.16; 'numpy': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'shorten': 0.16; 'subject:syntax': 0.16; 'wrote:': 0.18; 'trying': 0.21; 'cc:no real name:2**0': 0.21; 'programming': 0.21; 'interface': 0.23; 'header:In-Reply-To:1': 0.23; 'cc:2**0': 0.25; 'code': 0.25; 'math': 0.25; "i'm": 0.26; 'import': 0.28; 'cc:addr:python.org': 0.29; 'second': 0.29; 'module': 0.30; 'context,': 0.30; 'example': 0.30; 'equivalent': 0.30; 'wondering': 0.32; 'header:User-Agent:1': 0.33; 'try:': 0.34; 'things': 0.35; 'something': 0.36; 'could': 0.38; 'some': 0.38; 'except': 0.39; 'case': 0.39; 'subject:: ': 0.39; 'did': 0.40; 'within': 0.60; 'your': 0.61; 'full': 0.62; 'here': 0.65; 'confirm': 0.69; 'hate': 0.73; 'candide': 0.84; 'parity': 0.84; 'from.': 0.93 Date: Sat, 12 Nov 2011 06:43:06 -0600 From: Tim Chase User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.20) Gecko/20110826 Icedove/3.1.12 MIME-Version: 1.0 To: candide Subject: Re: Use and usefulness of the as syntax References: <4ebe5ee6$0$25872$426a74cc@news.free.fr> In-Reply-To: <4ebe5ee6$0$25872$426a74cc@news.free.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com 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: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1321101802 news.xs4all.nl 6897 [2001:888:2000:d::a6]:49142 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15623 On 11/12/11 05:56, candide wrote: > First, could you confirm the following syntax > > import foo as f > > equivalent to > > import foo > f = foo and the issuing "del 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 last case, I can see no point Without context, I'm guessing the last one is merely keeping parity in a block that reads: try: import cPickle as pickle except ImportError: import pickle as pickle > So what is the pragmatics of the as syntax ? The most common use-case I see is your first: to shorten a frequently-used namespace. I do this frequently with import Tkinter as tk which makes it obvious where things are coming from. I hate trying to track down variable-names if one did something like from Tkinter import * The second big use case I see regularly is the full example (above): try to import a faster/native module that shares an interface with a pure-python implementation. However in the above, the "import pickle as pickle" is a uselessly redundant. -tkc