1
这段代码有很多错误,但我想知道是否有人可以具体向我解释什么是“没有全局回溯发现”错误和“自身不是第一个方法参数?”。以下分别发生在第16行和第28行。Python检测代码中的错误
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行怎么样? – python5
在第16行中,你忘记了一个班级内每个功能都需要的“自我”(请参阅答案) –
它不具备*。你总是可以用'@ classmethod'装饰它来解决这个问题。 – Makoto