gpt4 book ai didi

Python 检测代码中的错误

转载 作者:行者123 更新时间:2023-11-30 23:39:35 25 4
gpt4 key购买 nike

这段Python代码有很多错误,但我想知道是否有人可以具体向我解释“没有找到全局回溯”错误和“self不是第一个方法参数?”以下内容分别发生在第 16 行和第 28 行。

 1   #! /usr/bin/env python
2
3 'Example errors caught by PyChecker'
4
5 import string
6
7 metaslash = 1
8
9 def printNames():
10 neal = 'neal'
11 michelle = 'michele'
12 eric = 5
13 print "Local values: %(neal)S %(michele)s %(eric)" % locals()
14
15 class Nothing:
16 def printValue(value):
17 print value
18 def set(self, value):
19 self.value = value
20
21 def tryToDoSomething(self, value):
22 try:
23 import string
24 if not value:
25 raise RuntimeError, "Hey, there's no value"
26 printNames('a, b, c')
27 except:
28 traceback.print_exc()
29
30 def setGlobal(value=None):
31 print 'Old MetaSlash value is:', metaslash
32 metaslash = value
33 useless = Nothing(5)
34 print 'a useless value is:', useless.valeu

最佳答案

第 16 行应该是:

def printValue(self, value):

在第 28 行,您调用的回溯对象是什么? Python 没有找到它。

关于Python 检测代码中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13410736/

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