I created two files in python First one is mym.py
def hello():
print("Hello everyone")
return
def summ(x,y):
total=x+y
return total
and next one is abc.py
import mym
hello()
x=summ(3,4)
print(x)
And the error msg which I am getting is...both the files are in same working directory and there is no error of module not found...its giving error of function not defined.
Traceback (most recent call last):
File "C:/Users/Nisha/AppData/Local/Programs/Python/Python39/abc.py", line 3, in <module>
hello()
NameError: name 'hello' is not defined
Traceback (most recent call last):
File "C:/Users/Nisha/AppData/Local/Programs/Python/Python39/abc.py", line 3, in <module>
x=summ(3,4)
NameError: name 'summ' is not defined
What is the problem in function definition I am unable to trace...
U13-Forward
71.8k15 gold badges100 silver badges125 bronze badges
2 Answers 2
The abc.py needs to be changed to:
from mym import *
hello()
x=summ(3,4)
print(x)
Otherwise you cannot access the functions.
answered Dec 19, 2020 at 12:26
U13-Forward
71.8k15 gold badges100 silver badges125 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You can try like this:
import mym
mym.hello()
x = mym.summ(3,4)
print(x)
Comments
Explore related questions
See similar questions with these tags.
lang-py
mym.summ