This coding style bad practise?
bruno at modulix
onurb at xiludom.gro
Thu May 4 04:27:59 EDT 2006
Martin P. Hellwig wrote:
> Bruno Desthuilliers wrote:
> <cut>
>
>>
>> Why not just use the call operator instead ? ie:
>>
>> >>> id = IDGenerator(...)
>> >>> id()
>> 01_20060424_151903_1
>> >>> id()
>> 01_20060424_151905_2
>>
>
> Because of:
>
>>>>> id = IDGenerator("01",99)
>>>>> id()
>>
>> Traceback (most recent call last):
>> File "<pyshell#1>", line 1, in ?
>> id()
>> TypeError: 'IDGenerator' object is not callable
>>
>>>>>
Of course - you have to overload the call operator for this to work.
Just rename IDGenerator.__repr__ to IDGenerator.__call__, and I garantee
this will work - and will be *much* more cleaner than abusing __repr__.
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list
mailing list