Re: [Tutor] dictionaries, objects and scoping...

2008-01-22 Thread Tiger12506
Just a thought~ The built-in id() function can be useful in helping to sort out stuff. Returns a unique identifier for each object created so you can test whether a different name is a different object or just a different name for the same object. (This is what the 'is' operator does... Note:

Re: [Tutor] dictionaries, objects and scoping...

2008-01-22 Thread Alan Gauld
"John Morris" <[EMAIL PROTECTED]> wrote > So this seems like it will make scope/namespaces a bit > interesting... namespaces in python are literally that, they are spaces where *names* are visible. Objects are something else entirely and assignment only pins a name to an object. So in Python na

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread John Morris
Thanks. I think this is understood better now. Thanks to everyone for their help. I was running low on ways to express this for clearer understanding. Awesomeness once again from [EMAIL PROTECTED] - John On Jan 21, 2008 10:18 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > John Morris wrote: > >

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread Kent Johnson
John Morris wrote: > Ahhh. so namespaces are scoped, not objects... I would say names are scoped, but I guess namespaces are too. > You have to keep your objects separate (and make copies when needed), Yes > Python just keeps namespaces (names that refer to an object) scoped > according to it

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread John Fouhy
On 22/01/2008, John Morris <[EMAIL PROTECTED]> 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. Massi

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread John Morris
Ahhh. so namespaces are scoped, not objects... You have to keep your objects separate (and make copies when needed), Python just keeps namespaces (names that refer to an object) scoped according to it's rules: http://docs.python.org/ref/naming.html So if you create an object way up in terms of sco

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread Kent Johnson
John Morris wrote: > Thanks, > > so I could/should do > > self.ot = Bar(self.name.copy()) instead Yes, if you want a copy you have to ask for it. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread John Morris
So this seems like it will make scope/namespaces a bit interesting... Any good references on why this is this way? I.e., why assignment passes across scopes instead of copy. Or is it just explicit versus implicit? On Jan 21, 2008 9:32 PM, John Fouhy <[EMAIL PROTECTED]> wrote: > On 22/01/2008,

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread Kent Johnson
John Morris wrote: > Does it have something to do with: > http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm > > And if so can anyone explain it a bit for me, I'm being slow tonight. > > I thought each class got it's own namespace and this sharing of mutable > objects is c

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread John Fouhy
On 22/01/2008, John Morris <[EMAIL PROTECTED]> wrote: > I thought each class got it's own namespace and this sharing of mutable > objects is confusing me. Each class gets its own namespace, but names are different from objects. For example: >>> x = [1, 2, 3] >>> y = x >>> y.append(4) >>> x [1, 2

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread John Morris
Thanks, so I could/should do self.ot = Bar(self.name.copy()) instead On Jan 21, 2008 9:25 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > John Morris wrote: > > > Why does the pop in the Bar class nuke the srv k & v from Foo.name > > as well? > > Because they are both names for

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread John Morris
Does it have something to do with: http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm And if so can anyone explain it a bit for me, I'm being slow tonight. I thought each class got it's own namespace and this sharing of mutable objects is confusing me. Thanks. On Jan 21,

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread Kent Johnson
John Morris wrote: > Why does the pop in the Bar class nuke the srv k & v from Foo.name > as well? Because they are both names for the same dict. Assignment in Python does not copy values; it binds a name to a value. Some good references: http://effbot.org/zone/python-objects