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
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
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
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
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?
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
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
> 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
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
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
> > 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
> >
> >
> > 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
> >
> >
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
>
13 matches
Mail list logo