Peter Otten wrote:
> collections.namedtuple is a convenient struct replacement -- if you don't
> mind that it is immutable.
Thanks you and also Steven for mentioning this, it is an even better
replacement for what I had in mind!
Uli
--
Domino Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsg
Ulrich Eckhardt wrote:
> Peter Otten wrote:
>> Examples for classes that don't accept attributes are builtins
>> like int, tuple, and -- obviously -- dict. You can make your own
>> using the __slot__ mechanism:
>>
> class A(object):
>> ... __slots__ = ["x", "y"]
>> ...
> a = A()
>
Ulrich Eckhardt wrote:
> Peter Otten wrote:
>> Examples for classes that don't accept attributes are builtins
>> like int, tuple, and -- obviously -- dict. You can make your own
>> using the __slot__ mechanism:
>>
> class A(object):
>> ... __slots__ = ["x", "y"]
>> ...
> a = A()
>
Am 29.06.2011 16:58, schrieb Ulrich Eckhardt:
> Now, follow-up question:
> 1. The slots are initialized to None, right? Or are they just reserved? IOW,
> would "print a.x" right after creation of the object print anything or raise
> an AttributeError?
No, slots don't have a default value. It wou
Peter Otten wrote:
> Examples for classes that don't accept attributes are builtins
> like int, tuple, and -- obviously -- dict. You can make your own
> using the __slot__ mechanism:
>
class A(object):
> ... __slots__ = ["x", "y"]
> ...
a = A()
a.x = 42
a.y = "yadda"
a
AlienBaby wrote:
> I'm just wondering why something is so, and whats going on under the
> hood.
>
> Now and again I use something like
>
> class empty(object):
> pass
>
>
> simply so I can make an instance, and set some attributes on it.
>
> a=empty()
> a.whatever=something
>
>
> Poking ar
Hi,
I'm just wondering why something is so, and whats going on under the
hood.
Now and again I use something like
class empty(object):
pass
simply so I can make an instance, and set some attributes on it.
a=empty()
a.whatever=something
Poking around with this, I assumed I could instead say