开发者

Trouble importing a Python module

开发者 https://www.devze.com 2023-01-01 13:20 出处:网络
I have a Python project with 2 files: epic.py site.py in the epic.py I have the lines from site import * bark()

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开发者_如何学C():
    print('arf!')

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

this is weird.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消