importing module versus using function?

gujax rjngrj2010 at
Tue Jan 31 10:08:43 EST 2012

I am confused on this quite bad!!
If I have this typed in interactive python:

>>import numpy

>>def dummy():
   return y

and then
>>s = dummy()
>>array[1. , 1.1,  1.2........]

 it works.

But if I have a module called, whose code is

def dummy():
   return y

and now if I do the following:

>>import numpy
>>from example import *

The above sequence does not work. It gives an error saying global
variable numpy not defined.

I understand that when I import a module it gets imported after
getting compiled and therefore, the module should
have a statement "import numpy" at its start.

But what if I just want to use the function 'dummy'?

I tried the following:
from example import dummy
and then try to use the function, it still gives me 'global name numpy
not defined'!

Why is that happening?
Any pointers please.

More information about the Python-list mailing list