Re: Dictionaries and dot notation

2007-04-23 Thread Bruno Desthuilliers
Martin Drautzburg a écrit : > Daniel Nogradi wrote: > > > What if I want to create a datastructure that can be used in dot notation without having to create a class, i.e. because those objects have no behavior at all? >>> >>>A class inheriting from dict and implementing __getattr__ a

Re: Dictionaries and dot notation

2007-04-23 Thread Antoon Pardon
On 2007-04-22, Martin Drautzburg <[EMAIL PROTECTED]> wrote: > Daniel Nogradi wrote: > > >>> > What if I want to create a datastructure that can be used in dot >>> > notation without having to create a class, i.e. because those >>> > objects have no behavior at all? >>> >>> A class inheriting from d

Re: Dictionaries and dot notation

2007-04-23 Thread Gabriel Genellina
En Mon, 23 Apr 2007 03:14:32 -0300, Martin Drautzburg <[EMAIL PROTECTED]> escribió: > I did not notice that I can use a single class (or a module) for > all my datastructures, because I can "plug in" new attributes into the > instance without the class knowing about them. > > I was mistaken to b

Re: Dictionaries and dot notation

2007-04-22 Thread Martin Drautzburg
Alex Martelli wrote: > Martin Drautzburg <[EMAIL PROTECTED]> wrote: > >> > mydata = data( ) >> > mydata.foo = 'foo' >> > mydata.bar = 'bar' >> > >> > print mydata.foo >> > print mydata.bar >> >> I am aware of all this. >> Okay let me rephrase my question: is there a way of using dot >> notation

Re: Dictionaries and dot notation

2007-04-22 Thread Alex Martelli
Martin Drautzburg <[EMAIL PROTECTED]> wrote: > > mydata = data( ) > > mydata.foo = 'foo' > > mydata.bar = 'bar' > > > > print mydata.foo > > print mydata.bar > > I am aware of all this. > Okay let me rephrase my question: is there a way of using dot notation > without having to create a class?

Re: Dictionaries and dot notation

2007-04-22 Thread Ben Finney
Martin Drautzburg <[EMAIL PROTECTED]> writes: > Okay let me rephrase my question: is there a way of using dot > notation without having to create a class? Dot notation, e.g. 'foo.bar', is parsed by the interpreter as "access the attribute named 'bar' of the object 'foo'". Objects have attributes

Re: Dictionaries and dot notation

2007-04-22 Thread Martin Drautzburg
Daniel Nogradi wrote: >> > What if I want to create a datastructure that can be used in dot >> > notation without having to create a class, i.e. because those >> > objects have no behavior at all? >> >> A class inheriting from dict and implementing __getattr__ and >> __setattr__ should do the tri

Re: Dictionaries and dot notation

2007-04-22 Thread Martin Drautzburg
> mydata = data( ) > mydata.foo = 'foo' > mydata.bar = 'bar' > > print mydata.foo > print mydata.bar I am aware of all this. Okay let me rephrase my question: is there a way of using dot notation without having to create a class? -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionaries and dot notation

2007-04-22 Thread Bruno Desthuilliers
Martin Drautzburg a écrit : > This may be pretty obvious for most of you: > > When I have an object (an instance of a class "Foo") I can access > attributes via dot notation: > > aFoo.bar > > however when I have a dictionary > > aDict = {"bar":"something"} > > I have to write

Re: Dictionaries and dot notation

2007-04-22 Thread Bruno Desthuilliers
Bruno Desthuilliers a écrit : > Martin Drautzburg a écrit : > >> This may be pretty obvious for most of you: >> >> When I have an object (an instance of a class "Foo") I can access >> attributes via dot notation: >> >> aFoo.bar >> >> however when I have a dictionary >> aDict = {"ba

Re: Dictionaries and dot notation

2007-04-22 Thread Daniel Nogradi
> > This may be pretty obvious for most of you: > > > > When I have an object (an instance of a class "Foo") I can access > > attributes via dot notation: > > > > aFoo.bar > > > > however when I have a dictionary > > > > aDict = {"bar":"something"} > > > > I have to write > > > >

Re: Dictionaries and dot notation

2007-04-22 Thread Daniel Nogradi
> > This may be pretty obvious for most of you: > > > > When I have an object (an instance of a class "Foo") I can access > > attributes via dot notation: > > > > aFoo.bar > > > > however when I have a dictionary > > > > aDict = {"bar":"something"} > > > > I have to write > > > >

Re: Dictionaries and dot notation

2007-04-22 Thread Stefan Behnel
Martin Drautzburg wrote: > This may be pretty obvious for most of you: > > When I have an object (an instance of a class "Foo") I can access > attributes via dot notation: > > aFoo.bar > > however when I have a dictionary > > aDict = {"bar":"something"} > > I have to write >