global name 'sqrt' is not defined
M.-A. Lemburg
mal at egenix.com
Thu Feb 5 07:01:33 EST 2009
On 2009-02-05 10:08, Nick Matzke wrote:
> Hi all,
>
> So, I can run this in the ipython shell just fine:
>
> ===========
> a = ["12", "15", "16", "38.2"]
> dim = int(sqrt(size(a)))
>
> dim
>>2
> ===========
>
>
> But if I move these commands to a function in another file, it freaks out:
You need to add:
from math import sqrt
> =================================
> a = distances_matrix.split('\t')
> from LR_run_functions_v2 import make_half_square_array
> d = make_half_square_array(a)
>
>>
> ---------------------------------------------------------------------------
> NameError Traceback (most recent call last)
>
> /bioinformatics/phylocom/<ipython console> in <module>()
>
> /bioinformatics/phylocom/_scripts/LR_run_functions_v2.py in
> make_half_square_array(linear_version_of_square_array)
> 1548
> 1549 a = linear_version_of_square_array
> -> 1550 dim = int(sqrt(size(a)))
> 1551
> 1552
>
> NameError: global name 'sqrt' is not defined
>
> =================================
>
>
>
>
> Here's the function in LR_run_functions_v2.py
>
> ==========================
> def make_half_square_array(linear_version_of_square_array):
>
> a = linear_version_of_square_array
> dim = int(sqrt(size(a)))
> ==========================
>
>
>
> Any ideas? If I do something like "import math" in the subfunction,
> then the error changes to "global name 'math' is not defined".
>
> Thanks!
> Nick
>
>
>
>
>
>
>
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Feb 05 2009)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
More information about the Python-list
mailing list