1

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.

3
  • You seem to be saying that goodbye() is in mymodule.py. What file is the import in? Commented Aug 12, 2022 at 22:55
  • please add the complete traceback! Commented Aug 12, 2022 at 22:55
  • Your code sample seems to be the mymodule code. Why would it need to import itself? Commented Aug 13, 2022 at 0:29

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.