This coding style bad practise?

keirr keir.robinson at gmail.com
Wed May 3 17:13:28 EDT 2006


Martin P. Hellwig wrote:
> Hi all,
>
> I created a class which creates a relative unique id string, now my
> program just works fine and as expected but somehow I get the feeling
> that I misused the __repr__ since I guess people expect to 'execute' a
> function in an instance instead of using it's representation string of
> the instance itself, could you elaborate whether you find this bad
> practice and if yes what would have been a better way to do it?
>
> TIA
>

Rather than comment on the style of using a class, I'll just suggest an
alternative.
You can use a generator function, which yields the next id when called;
at least that's 
how I'd implement an IDgenerator.

Cheers,

 Keir.




More information about the Python-list mailing list