Python is wierd!

Bjorn Pettersen bjorn at roguewave.com
Thu Jul 27 14:00:02 EDT 2000


David Bolen wrote:
> 
> Greg Ewing <to_get_my_address at see.my.signature> writes:
> 
> > And to answer your question, yes, you can create an instance
> > variable at any time simply by executing "instance.name = value".
> 
> Which actually leads to an interesting question relating to a point
> that I'm curious how others handle.
> 
> If I'm going to package up some state (various bits of information)
> into a class (aka using one as a structure - data only), one approach
> could be to define an empty class:
> 
>     class MyInfo:
>         pass
> 
> and then whenever I need to later:
> 
>     newstate = MyInfo()
>     newstate.variable = value
>     newstate.other_variable = value

[snip]

Whenever I feel the need to do something like this I use a dictionary
instead...

-- bjorn




More information about the Python-list mailing list