3

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?

Ethan Furman
  • 63,992
  • 20
  • 159
  • 237
Jake Dewit
  • 57
  • 1
  • 3
  • 1
    It would be helpful, both to you and to the people answering your questions, to try and create a more minimal example before pasting it. If you really can't figure out what's causing the problem, then it's better to paste the whole script than a snippet that won't actually run, but it's better yet to create a small snippet that *does* actually run, and produce the error. – Glyph Oct 29 '11 at 01:40

2 Answers2

11

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.

Larry Lustig
  • 49,320
  • 14
  • 110
  • 160
  • 3
    I'm not convinced "beauty" is the right word. You can't argue the fact, though, that python is a terrific language all things considered. For me, it's well worth putting up with the whitespace issue. – Bryan Oakley Oct 29 '11 at 02:35
4

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.

Russell Borogove
  • 18,516
  • 4
  • 43
  • 50