Asaf
Asaf

Reputation: 8206

Trouble importing a Python module

I have a Python project with 2 files: epic.py site.py

in the epic.py I have the lines

from site import *
bark()

in site.py I have the lines

def bark():
    print('arf!')

when I try to run epic.py, it returns "bark is not defined"
this is weird.

Upvotes: 2

Views: 1916

Answers (2)

Santa
Santa

Reputation: 11547

That's because site is also the name of a built-in module. You weren't really importing your custom site module. If you change the name to, say, site_.py and import accordingly, it'll work.

Upvotes: 1

Justin Peel
Justin Peel

Reputation: 47082

Try renaming site.py to mysite.py or something like that because there is a standard Python site module.

Upvotes: 5

Related Questions