Subclass str: where is the problem?

2006-04-24 Thread pascal . parent
Hello, can anybody explain/help me: Python 2.4.2 (#2, Sep 30 2005, 21:19:01) [GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2 class Upper(str): def __new__(cls, value): return str.__new__(cls, value.upper()) u = Upper('test') u 'TEST' type(u) u = Upper('') u '' type(u)

Re: Subclass str: where is the problem?

2006-04-24 Thread pascal . parent
This is good... try this: value = 'test' value 'test' type(value) value = type(value) is type('') and Upper(value) or value value 'TEST' type(value) value = 1 value 1 type(value) value = type(value) is type('') and Upper(value) or value value 1 type(value) -- http://mail.python.org/mailman

Re: Subclass str: where is the problem?

2006-04-24 Thread pascal . parent
Effectively. Thanks a lot Peter and Harold. -- http://mail.python.org/mailman/listinfo/python-list

__getattribute__ and __slots__

2006-04-14 Thread pascal . parent
Hi, I try to define a (new-style) class who: - have a __slots__ defined to be strict attributes, - return None if the attribute is 'ok' but not set, or raise a 'normal' error if the attribute isn't in __slots__. This code runs, but is it the good way? Thanks. class test(object): __slots__ =