parastoo nik
parastoo nik

Reputation: 11

AttributeError in module

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.

Upvotes: 1

Views: 44

Answers (1)

Robert Haas
Robert Haas

Reputation: 900

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

Upvotes: 1

Related Questions