'import x as y' stops the show (was: Re: [Python-Dev] [Patch #101135] 'import x as y' and 'from x import y as z' (fwd)) (original) (raw)
Peter Schneider-Kamp nowonder@nowonder.de
Thu, 10 Aug 2000 08:10:13 +0000
- Previous message: 'import x as y' stops the show (was: Re: [Python-Dev] [Patch #101135] 'import x as y' and 'from x import y as z' (fwd))
- Next message: 'import x as y' stops the show (was: Re: [Python-Dev] [Patch #101135] 'import x as y' and 'from x import y as z' (fwd))
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Thomas Wouters wrote:
'join as j' ? What would it do ? Import all symbols from 'string' into a new namespace 'j' ? How about you do 'import string as j' instead ? It means you will still be able to do 'j.somevar', which you probably wouldn't in your example, but I don't think that's enough reason :P
Okay, your misunderstanding of the semantics I had in mind are reason enough <0.5 wink>.
from string import *, join as j (or equivalently) from string import join as j, *
would (in my book) import all "public" symbols from string and assign j = join.
Assuming we have a Tkinter app (where all the tutorials do a 'from Tkinter import *') and we don't like 'createtimerhandle'. Then the following would give us tk_timer instead while still importing all the stuff from Tkinter with their regular names:
from Tkinter import *, createtimerhandle as tk_timer
An even better way of doing this were if it would not only give you another name but if it would not import the original one. In this example our expression would import all the symbols from Tkinter but would rename createtimerhandle as tk_timer. In this way you could still use * if you have a namespace clash. E.g.:
from Tkinter import *, mainloop as tk_mainloop
def mainloop(): <do some really useful stuff calling tk_mainloop()>
if name == 'main': mainloop()
Peter
Peter Schneider-Kamp ++47-7388-7331 Herman Krags veg 51-11 mailto:peter@schneider-kamp.de N-7050 Trondheim http://schneider-kamp.de
- Previous message: 'import x as y' stops the show (was: Re: [Python-Dev] [Patch #101135] 'import x as y' and 'from x import y as z' (fwd))
- Next message: 'import x as y' stops the show (was: Re: [Python-Dev] [Patch #101135] 'import x as y' and 'from x import y as z' (fwd))
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]