gpt4 book ai didi

python - 名称错误 : global name is not defined

转载 作者:IT老高 更新时间:2023-10-28 22:18:40 30 4
gpt4 key购买 nike

我在 Mac OS X 上使用 Python 2.6.1。

我有两个简单的 Python 文件(如下),但是当我运行时

python update_url.py

我上了终端:

Traceback (most recent call last):
File "update_urls.py", line 7, in <module>
main()
File "update_urls.py", line 4, in main
db = SqliteDBzz()
NameError: global name 'SqliteDBzz' is not defined

我尝试以不同的方式重命名文件和类,这就是为什么末端有 x 和 z。 ;)

文件 sqlitedbx.py

class SqliteDBzz:
connection = ''
curser = ''

def connect(self):
print "foo"

def find_or_create(self, table, column, value):
print "baar"

文件 update_url.py

import sqlitedbx

def main():
db = SqliteDBzz()
db.connect

if __name__ == "__main__":
main()

最佳答案

你需要做的:

import sqlitedbx

def main():
db = sqlitedbx.SqliteDBzz()
db.connect()

if __name__ == "__main__":
main()

关于python - 名称错误 : global name is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3977167/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com