[Tutor] dictionaries, objects and scoping...
John Fouhy
john at fouhy.net
Tue Jan 22 04:18:18 CET 2008
On 22/01/2008, John Morris <jrmorrisnc at gmail.com> wrote:
> So if you create an object way up in terms of scope (global), then all
> python does is handle what names are available in a given scope to refer to
> it. If you want a separate object you have to take care of that yourself.
> Efficient. Massive potential for gotchas, especially with some of python's
> cleverness in terms of scoping rules.
There is potential for gotchas, but it's reduced by the fact that
integers and strings are both immutable. For example:
>>> x = 'foo'
>>> y = x
>>> y is x # this tests whether x and y are different names for the
same object
True
>>> y += 'bar' # this is equivalent to: y = y + 'bar'
>>> y is x
False
>>> y, x
('foobar', 'foo')
(this is why there is no '.append()' method for strings)
--
John.
More information about the Tutor
mailing list