views:

37

answers:

2

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.

+4  A: 

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

Justin Peel
No wonder I didn't find anything about it in the documentation..Is there a short list of forbidden names ?
Asaf
http://docs.python.org/library/ - using a quick search at the left displays everything related to that (first result with 'site' was the module)
wvd
You can always try importing the name to check it before using it. You can also call `dir()` on the imported module to see if the functions in the module are what you would expect them to be.
Justin Peel
+1  A: 

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.

Santa