[Sndobj-devel] Fwd: importing namespaces/modules 2of3
Status: Abandoned
Brought to you by:
veplaini
From: sonify <so...@av...> - 2007-01-21 06:07:50
|
Begin forwarded message: > From: Piet van Oostrum <pi...@cs...> > Date: 19 January 2007 8:37:00 PM > To: David Worrall <vi...@av...> > Cc: Pyt...@py... > Subject: Re: [Pythonmac-SIG] importing namespaces/modules > > I should add another difference in the behaviour of variables > import in one > or the other way. This can lead to subtle differences. > > If you use 'from module import x, y' (or 'from module import *') > Python > makes new `bindings' of the names `x' and `y' in the importing > module with > the values these names had in the imported module. However they are > independent of the original ones. So if you execute an assignment > to x in > the original module, e.g. in a function that was defined there and > that you > also imported, the change in x is not reflected in the imported x, > and vice > versa. This can lead to unexpected behaviour. > > If, however, you say 'import module' and then use module.x, then it > is the > same variable, and changes in the imported module's x will be > visible in > the importing module's module.x and vice versa. > > -- > Piet van Oostrum <pi...@cs...> > URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] > Private email: pi...@va... > _________________________________________________ experimental polymedia: www.avatar.com.au Sonic Communications Research Group, University of Canberra: www.canberra.edu.au/vc-forum/scrg vip=Verbal Interactivity Project experimental polymedia: www.avatar.com.au Sonic Communications Research Group, University of Canberra: www.canberra.edu.au |