Re: Use and usefulness of the as syntax

2011-11-17 Thread alex23
On Nov 18, 1:48 am, candide wrote: > # a.py > import math as _math > > # b.py > from a import * > > print _math.sin(0)       # raise a NameError > print math.sin(0)        # raise a NameError > > so the as syntax is also seful for hiding name, isn'it ? Not exactly. It's the * import mechanism her

Re: Use and usefulness of the as syntax

2011-11-17 Thread candide
Thanks to all Le 12/11/2011 13:27, Chris Angelico a écrit : > On Sat, Nov 12, 2011 at 10:56 PM, candide wrote: >> import foo as f >> >> equivalent to >> >> import foo >> f = foo >> > > Not quite, it's closer to: > > import foo > f = foo > del foo > Le 12/11/2011 13:43, Tim Chase a écrit :

Re: Use and usefulness of the as syntax

2011-11-17 Thread candide
Le 12/11/2011 13:29, Arnaud Delobelle a écrit : -- 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 *" To contextualize more,

Re: Use and usefulness of the as syntax

2011-11-13 Thread Terry Reedy
On 11/13/2011 3:55 AM, 0xfn wrote: On Nov 12, 7:48 am, Rafael Durán Castañeda wrote: El 12/11/11 13:43, Tim Chase escribió:> I hate trying to track down variable-names if one did something like from Tkinter import * +1 Really, this questionable code is always mentioned as example

Re: Use and usefulness of the as syntax

2011-11-13 Thread 0xfn
On Nov 12, 7:48 am, Rafael Durán Castañeda wrote: > El 12/11/11 13:43, Tim Chase escribió:>   I hate trying to track down > variable-names if one did something like > > >   from Tkinter import * > > +1 Really, this questionable code is always mentioned as example in Tkinter tuts. IMHO much bette

Re: Use and usefulness of the as syntax

2011-11-12 Thread Mel Wilson
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

Re: Use and usefulness of the as syntax

2011-11-12 Thread Tim Wintle
On Sat, 2011-11-12 at 12:56 +0100, candide wrote: > So what is the pragmatics of the as syntax ? Another case: try: import json except: import simplejson as json (same goes for several modules where the C implementation may or may not be available) Tim -- http://mail.python.org/mail

Re: Use and usefulness of the as syntax

2011-11-12 Thread Rafael Durán Castañeda
El 12/11/11 13:43, Tim Chase escribió: I hate trying to track down variable-names if one did something like from Tkinter import * +1 -- http://mail.python.org/mailman/listinfo/python-list

Re: Use and usefulness of the as syntax

2011-11-12 Thread Tim Chase
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

Re: Use and usefulness of the as syntax

2011-11-12 Thread Arnaud Delobelle
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

Re: Use and usefulness of the as syntax

2011-11-12 Thread Chris Angelico
On Sat, Nov 12, 2011 at 10:56 PM, candide 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. S

Use and usefulness of the as syntax

2011-11-12 Thread candide
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