when I write my functions in mymodule and then import that show me this error:
def goodbye(name):
print(f'goodbye{name}')
def hello(name):
print(f'hello{name}')
import mymodule
mymodule.goodbye('nika')
Run
mymodule.goodbye('nika')
AttributeError: module 'mymodule' has no attribute 'goodbye'
I checked it many times but I couldn't solve it.
quamrana
39.5k13 gold badges57 silver badges77 bronze badges
1 Answer 1
I think this is what you want to do:
File 1: mymodule.py
def goodbye(name):
print(f'goodbye {name}')
def hello(name):
print(f'hello {name}')
File 2: test.py
import mymodule
mymodule.goodbye('john')
Run file 2 on the command line, so that it imports file 1 and uses a function in it:
python test.py
Result:
goodbye john
answered Aug 12, 2022 at 23:03
Robert Haas
1,0134 silver badges16 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
goodbye()is inmymodule.py. What file is theimportin?mymodulecode. Why would it need to import itself?