__slots__ and class attributes
I'm running into a something unexpected for a new-style class that has both a class attribute and __slots__ defined. If the name of the class attribute also exists in __slots__, Python throws an AttributeError. Is this by design (if so, why)? class A( object ): __slots__ = ( 'value', ) value = 1 def __init__( self, value = None ): self.value = value or A.value a = A() print a.value Traceback (most recent call last): File "t1.py", line 8, in ? a = A() File "t1.py", line 6, in __init__ self.value = value or A.value AttributeError: 'A' object attribute 'value' is read-only -- http://mail.python.org/mailman/listinfo/python-list
Re: __slots__ and class attributes
Steven Bethard wrote: > But why do you want a class level attribute with the same name as an > instance level attribute? I would have written your class as: > > class A(object): > __slots__ = ['value'] > def __init__(self, value=1): > self.value = value > > where the default value you put in the class is simply expressed as a > default value to the __init__ parameter. Thanks for your explanation. The reason why I was doing it was to have class-level defaults, so that one can easily adjust how new instances will be made. I'm doing it now with capitilized class attribute names to avoid the name clash. -- -- Ewald -- http://mail.python.org/mailman/listinfo/python-list
Re: directory bug on linux; workaround?
Russell E. Owen wrote: > It seems that the path was to a "fat" file partition and included a > directory name that was all uppercase. The directory was created, but > using lowercase. I'm not yet sure the version of python. > > The workaround for now is to not use fat file partitions. But I was > wondering if anyone had a better option? You can mount the FAT partition with the 'shortname' argument, i.e. put something like /dev/sda1 /usbkey auto umask=0,user,iocharset=iso8859-1,sync,kudzu,codepage=850,noauto,exec,users,shortname=winnt,check=s 0 0 in your /etc/fstab Btw, this is a general Linux problem and is not really related to Python (it also happens when working with shells or filemanagers). -- -- Ewald -- http://mail.python.org/mailman/listinfo/python-list
Re: cyclic data structures
John Salerno wrote: > I'm having some slight trouble understanding exactly why this creates an > infinite loop: > > L = [1, 2] > L.append(L) I tried this with Python 2.3.5 and it handles this tailbiter in a very pleasantly surprising way: >>> l = [ 0, 1 ] >>> l.append( l ) >>> l [0, 1, [...]] >>> l[2] [0, 1, [...]] >>> l[2][2][2][2][2][2][2][0] 1 The [...] I have never seen before anywhere, is it documented? -- -- Ewald -- http://mail.python.org/mailman/listinfo/python-list