Reputation: 1771
Good evenning guys,
I ve got that weird behavior. Any help would be appreciated.
Here is a function from a module called tankython, calling a function from a module called usual. However, it looks like Python refuses to recognize the function. Here is the code
#tankython.py
from usual import *
from get_data import *
from settings import *
from actif_class import *
def tanking(list_spreads,settings):
#### Tanking ####
fenetre = settings.fenetre
list_spread_exit,list_spread_temp= [],[]
ii= 0
for spread in list_spreads :
avc = ii * 100/float(len(list_spreads))
print "Be patient. Tanking in progress..." , avc,"%"
info = tankython (list_spreads,fenetre,ii)
list_spread_temp.append(info)
ii = ii + 1
list_spread_exit = check_list(list_spread_temp)
return list_spread_exit
#usual.py
def check_list(list_entry):
i = 0
while i < len(list_entry):
if list_entry[i] == 0 :
list_entry.pop(i)
else :
i = i+ 1
return list_entry
Here is the error message which I found really weird as I asked Py to import everything from usual.py:
File "tankython.py", line 77, in tanking
list_spread_exit = check_list(list_spread_temp)
NameError: global name 'check_list' is not defined
One last thing: eventually, if I put the function in tankython module, then Py accepts to goes through the entire process. However I really would like to know if there is anything I am doing wrong here.
Cheers guys
Upvotes: 4
Views: 6701
Reputation: 1771
I find another solution, although it is not the most elegan one, especially because it did not explain what went wrong. However, I renamed the entire module usual by f_usual and it is working perfectly fine.
Thanks for your help
Upvotes: 0
Reputation: 3782
Try to put file tankython.py and usual.py in the same folder and use the
from usual import check_list
instead of
from usual import *
May help. Or you can try:
import usual
Then change code like:
usual.check_list()
And
from module import *
is not a good way to import something if two packages have the same name functions.
Upvotes: 3