Python:“自我”是不是没有定义?

发布于 2024-12-12 09:25:14 字数 847 浏览 0 评论 0原文

回到同样令人困惑的脚本..我修复了很多间距问题...但似乎缺少更多?这有什么问题——它说第 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自此以后,行同陌路 2024-12-19 09:25:14

如果代码摘录准确地反映了程序中的内容,则问题在于您的 __init__ 构造函数中只有一行。您需要修复您的缩进。

Self 仅在成员函数中定义。您的非缩进代码不是构造函数的一部分,但实际上是在您导入您的类时运行的。

Python 的一大优点是它使用缩进来识别语句块,而不是花括号或 beginend。您必须正确使用缩进,以便解释器能够理解您的代码。

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 you import 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.

慢慢从新开始 2024-12-19 09:25:14

缩进在 Python 中很重要。 self 是在 __init__() 中定义的,因此假设您希望在第 332 行中引用 self,请将其缩进以匹配该行多于。

Indentation matters in Python. self is defined within the __init__(), so assuming you want that self to be referred to in line 332, indent it to match the line above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文