pep 8 constants

Brendan Miller catphive at catphive.net
Wed Jan 14 02:26:54 EST 2009


> FOO = 1
>
> def f(x=FOO):
>   ...
>
>
> Use this instead:
>
> def f(x=1):
>   ...


I tend to use constants as a means of avoiding the proliferation of
magic literals for maintenance reasons... Like say if your example of
FOO would have been used in 10 places. Maybe it is more pythonic to
simply denote such a thing as simply a normal variable? That doesn't
seem to give a hint that it shouldn't be assigned a second time.



More information about the Python-list mailing list