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

[Tutor] dictionaries, objects and scoping...

2008-01-21 Thread John Morris
class Foo: '''Represents a foo''' def __init__(self, name): '''Initializes the person's data''' self.name = name print '(Initializing %s)' % self.name self.ot = Bar(self.name) print '(After Other - %s)' % self.name class Bar: def __init__(self, name): self.name

[Tutor] float_info

2008-01-21 Thread Kent Johnson
This is probably of interest to Dick Moores at least... From What's New in Python 2.6 http://docs.python.org/dev/whatsnew/2.6.html [Note: A release date has not been set for Python 2.6] A new variable in the sys module, float_info, is an object containing information about the platform’s floati

Re: [Tutor] Programming Ideas, need some focus

2008-01-21 Thread Benjamin Eckenfels
On Fri, Jan 18, 2008 at 10:46:12AM -0500, "Simón A. Ruiz" wrote: > I'll second that. Me, too. Thanks for that hint. I currently have a great time with python challenge. I recommend it for everybody who like me has just finished the python basics an now is looking for an entertaining way to get