Python: "Self" is not not defined?

8.5k Views Asked by At

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?

2

There are 2 best solutions below

1
On

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.

0
On

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.