I created a module named code: code.py and wrote a simple function:
def main():
print("simple function")
I tried dropping this file inside site-packages and when I run:
import code
code.main()
I get the following error: AttributeError: module 'code' has no attribute 'main'.
Interestingly enough, if I rename the module to foo.py, this code works just fine:
import foo
foo.main()
Code isn't a reserved word so why can't I name a module code?
code
已经是一个Python模块,即正在导入的内容,而不是您的文件
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.