PyMyth: Global variables are evil... WRONG!

Tim Chase python.list at tim.thechases.com
Tue Nov 12 22:22:12 EST 2013


On 2013-11-12 18:45, Rick Johnson wrote:
> "math.pi" should be "math.PI".

It's a real shame that this fails:

  >>> math.PI = math.pi

oh...wait...

> and PI should be a CONSTANT. And not just a pseudo constant, but a
> REAL constant that cannot be changed.

How much precision do you want?  Perhaps you really do want do just
use because you know you only have 2-3 places of precision in your
other numbers:

  math.pi = 3.14

Or maybe you want to monkey-patch in a fraction/decimal instead for
greater precision:

 math.pi = decimal.Decimal('3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679')

It comes back to Python being a language for consenting adults.

-tkc






More information about the Python-list mailing list