global name 'sqrt' is not defined

Scott David Daniels Scott.Daniels at Acm.Org
Thu Feb 5 16:54:40 CET 2009


M.-A. Lemburg wrote:
> On 2009-02-05 10:08, Nick Matzke wrote:
>> ..., I can run this in the ipython shell just fine:
>> a = ["12", "15", "16", "38.2"]
>> dim = int(sqrt(size(a)))
>> ...But if I move these commands to a function in another file, it freaks out:
> You need to add:
> 
> from math import sqrt
or:
     from cmath import sqrt
or:
     from numpy import sqrt

Each with their own, slightly different, meaning.
Hence the reason many of us prefer to import the module
and reference the function as a module attribute.

Note that _many_ (especially older) package documents describe
their code without the module name.  I believe that such behavior
is because, when working to produce prose about a package, it
feels too much like useless redundancy when describing each function
or class as "package.name".


--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list