Re: global name 'sqrt' is not defined
- From: Nick Matzke <matzke@xxxxxxxxxxxx>
- Date: Thu, 05 Feb 2009 16:48:09 -0800
OK, so the problem was that I had to exit ipython, re-enter it, and then import my module to get the errors to disappear. Thanks for the help!
(PS: Is there a way to force a complete reload of a module, without exiting ipython? Just doing the import command again doesn't seem to do it.)
Thanks!
Nick
Diez B. Roggisch wrote:
Nick Matzke schrieb:
Scott David Daniels wrote:M.-A. Lemburg wrote:On 2009-02-05 10:08, Nick Matzke wrote:or:..., I can run this in the ipython shell just fine:You need to add:
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:
from math import sqrt
from cmath import sqrt
or:
from numpy import sqrt
The weird thing is, when I do this, I still get the error:
============
nick@mws2[phylocom]|27> a = ["12", "15", "16", "38.2"]
nick@mws2[phylocom]|28> from LR_run_functions_v2 import make_half_square_array
nick@mws2[phylocom]|24> 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 from numpy import sqrt
1549 a = linear_version_of_square_array
-> 1550 dim = int(sqrt(size(a)))
1551
1552
NameError: global name 'sqrt' is not defined
nick@mws2[phylocom]|25>
============
Is there some other place I should put the import command? I.e.:
1. In the main script/ipython command line
2. In the called function, i.e. make_half_square_array() in LR_run_functions_v2.py
3. At the top of LR_run_functions_v2.py, outside of the individual functions?
The latter. Python's imports are always local to the module/file they are in, not globally effective.
Diez
--
http://mail.python.org/mailman/listinfo/python-list
--
====================================================
Nicholas J. Matzke
Ph.D. student, Graduate Student Researcher
Huelsenbeck Lab
Center for Theoretical Evolutionary Genomics
4151 VLSB (Valley Life Sciences Building)
Department of Integrative Biology
University of California, Berkeley
Lab websites:
http://ib.berkeley.edu/people/lab_detail.php?lab=54
http://fisher.berkeley.edu/cteg/hlab.html
Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370
Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html
Lab phone: 510-643-6299
Dept. fax: 510-643-6264
Cell phone: 510-301-0179
Email: matzke@xxxxxxxxxxxx
Mailing address:
Department of Integrative Biology
3060 VLSB #3140
Berkeley, CA 94720-3140
-----------------------------------------------------
"[W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together."
Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 14(1), 35-44. Fall 1989.
http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm
====================================================
.
- References:
- Re: global name 'sqrt' is not defined
- From: M.-A. Lemburg
- Re: global name 'sqrt' is not defined
- From: Scott David Daniels
- Re: global name 'sqrt' is not defined
- From: Nick Matzke
- Re: global name 'sqrt' is not defined
- From: Diez B. Roggisch
- Re: global name 'sqrt' is not defined
- Prev by Date: Using multiprocessing from a Windows service
- Next by Date: Re: subprocess returncode windows
- Previous by thread: Re: global name 'sqrt' is not defined
- Next by thread: Re: global name 'sqrt' is not defined
- Index(es):
Relevant Pages
|