Python:“自我”是不是没有定义?
回到同样令人困惑的脚本..我修复了很多间距问题...但似乎缺少更多?这有什么问题——它说第 332 行 self
未定义...
以下是该脚本上方和下方的几行,以防重要:
#-Whats being decompiled start
#map(None,*list) = zip(*list)
class areaset(top_tsv):
def __init__(self, file_name=0, version=0):
top_tsv.__init__(self, file_name, version)
self.frombin_map = [ <--- this is 332
('ID' ,{'t':'ulong','lpad':0x04}),
('Name' ,{'t':'str','s':0x48,'rpad':0x1C}),
('RGB color' ,{'t':'color','rpad':0x01}),
('Sound effect ID' ,{'t':'long'}),
('Color RGB' ,{'t':'rcolor','rpad':0x01}),
('Lighting RGB value' ,{'t':'rcolor','rpad':0x01}),
('Lighting angle' ,{'t':'float','s':0x03,'f':0x01}),
('Is it City?' ,{'t':'ubyte','rpad':0x03}),
]
我只是无法弄清楚,我无法现在想一想.. 还有许多其他“自我未定义”错误,但如果我解决了这个错误,那么至少我会知道如何解决其余问题。那么我需要做什么?
Back with the same confusing script.. there was A LOT of spacing issues that I fixed... but seem to be missing more? Whats wrong with this -- its saying line 332 self
is not defined...
Here are a few lines above and below that script in case it matters:
#-Whats being decompiled start
#map(None,*list) = zip(*list)
class areaset(top_tsv):
def __init__(self, file_name=0, version=0):
top_tsv.__init__(self, file_name, version)
self.frombin_map = [ <--- this is 332
('ID' ,{'t':'ulong','lpad':0x04}),
('Name' ,{'t':'str','s':0x48,'rpad':0x1C}),
('RGB color' ,{'t':'color','rpad':0x01}),
('Sound effect ID' ,{'t':'long'}),
('Color RGB' ,{'t':'rcolor','rpad':0x01}),
('Lighting RGB value' ,{'t':'rcolor','rpad':0x01}),
('Lighting angle' ,{'t':'float','s':0x03,'f':0x01}),
('Is it City?' ,{'t':'ubyte','rpad':0x03}),
]
I just cant figure it out, I can't think right now.. there are many other "self is not defined" errors, but if I fix this one, then at least I'll know how to fix the rest. So what do I need to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果代码摘录准确地反映了程序中的内容,则问题在于您的
__init__
构造函数中只有一行。您需要修复您的缩进。Self
仅在成员函数中定义。您的非缩进代码不是构造函数的一部分,但实际上是在您导入
您的类时运行的。Python 的一大优点是它使用缩进来识别语句块,而不是花括号或
begin
、end
。您必须正确使用缩进,以便解释器能够理解您的代码。If the code excerpt accurately reflects what's in your program the problem is that you have only a single line in your
__init__
constructor. You need to fix your indentation.Self
is only defined in member functions. Your non-indented code is not part of the constructor, but is actually getting run when youimport
your class.One of the great beauties of Python is that it uses indenting to recognize statement blocks rather than curly braces or
begin
,end
. You must use the indenting correctly for the interpreter to understand your code.缩进在 Python 中很重要。
self
是在__init__()
中定义的,因此假设您希望在第 332 行中引用self
,请将其缩进以匹配该行多于。Indentation matters in Python.
self
is defined within the__init__()
, so assuming you want thatself
to be referred to in line 332, indent it to match the line above.