I couldn't use the sign funcion inside of another function

Julio Sergio juliosergio at gmail.com
Mon Apr 23 14:29:24 EDT 2012


I want to use the sign function. When I use it in in-line mode works pretty 
well:

   : sign(-20)
   : -1

However, I wrote the following code in a file, say, pp.py

def tst(x):
    s = sign(x)
    return(s)

Then I tried to import into my session:

  : from pp import *

When I try to use tst, this is what I get:

  ------------------------
  Traceback (most recent call last):
    File "<ipython console>", line 1, in <module>
    File "pp.py", line 9, in tst
      s = sign(x)
  NameError: global name 'sign' is not defined


Do you have any idea why is this happening?


Thanks,

 -- Sergio.





More information about the Python-list mailing list