[FRPythoneers] Need a Dope Slap

Sean Reifschneider jafo at tummy.com
Wed Feb 20 12:31:21 MST 2002

On Wed, Feb 20, 2002 at 11:05:44AM -0800, Keith Hellman wrote:
>I used to think that 
>	from foo import a, b, c as d

The "from x import y" syntax loads the symbol "y" from the module "x" into
the current local name-space.  Assignment to "y" will set up a new value
associated with that name in the current name-space, instead of updating
the module, as you've seen.

However, if you do "import x", that gives you a new namespace, "x", which
you can modify using "x.y = 5", for example.  In that case, if multiple
modules import "x", they will see the new value of the "y" attribute (since
it was set in the "x" namespace, instead of in the local name-space...

The "as" portion just lets you rename a symbol.  "import x as w" simply
changes the name "x" to "w", so you'd do "w.y = 5".  It doesn't change how
the importing or namespace rules happen...

I hope this helps,
 "Action...  Romance...  Welding...  That movie has everything."
                 -- Evelyn Mitchell speaking about _Subway_, 1998
Sean Reifschneider, Inimitably Superfluous <jafo at tummy.com>
tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python

More information about the FRPythoneers mailing list