NameError:未定义全局名称 [英] NameError: global name is not defined
本文介绍了NameError:未定义全局名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Mac OS X上使用Python 2.6.1。
I'm using Python 2.6.1 on Mac OS X.
我有两个简单的Python文件>
I have two simple Python files (below), but when I run
python update_url.py
$ b b
我在终端上:
I get on the terminal:
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在末尾。 ;)
I tried renaming the files and classes differently, which is why there's x and z on the ends. ;)
class SqliteDBzz:
connection = ''
curser = ''
def connect(self):
print "foo"
def find_or_create(self, table, column, value):
print "baar"
文件update_url.py
File 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()
这篇关于NameError:未定义全局名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文