I am currently working on python programming.
class A:
def LoadPosition(self):
FILE = open('a.txt', "r+")
i = 0
for node in self.nodes:
line = FILE.readline()
if i == 0:
scaling_factor == float(line)
i += 1
else:
tmpn, tmpx, tmpy, tmpa = line.split('\t')
node.id = tmpn
node.coordinate_x = float(tmpx)
node.coordinate_y = float(tmpy)
node.area = int(tmpa)
FILE.close()
It was fine before, but all of sudden, it shows the NameError message. Please help me out.
Thanks in advance.
You’re mixing spaces and tabs in strange ways, which is probably confusing Python. Here’s what I get when I copy-and-paste your code from the edit window:
[Note that if someone copies code from the posted question and not the raw edit window, this might not happen — at least sometimes it’s suppressed seeing the original tabs for me — and so people who try your code might not have any problems.]
Step #1: run your code using
python -tt yourfilenamehere.pyto confirm that it’s a tab error.Step #2: switch to using four-space tabs everywhere.