Re: using an instance of Object as an empty class

2011-06-30 Thread Ulrich Eckhardt
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

Re: using an instance of Object as an empty class

2011-06-29 Thread steve+comp . lang . python
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() >

Re: using an instance of Object as an empty class

2011-06-29 Thread Peter Otten
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() >

Re: using an instance of Object as an empty class

2011-06-29 Thread Christian Heimes
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

Re: using an instance of Object as an empty class

2011-06-29 Thread Ulrich Eckhardt
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

Re: using an instance of Object as an empty class

2011-06-29 Thread Peter Otten
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

using an instance of Object as an empty class

2011-06-29 Thread AlienBaby
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