Unfortunately that still didn’t work. There is no indentation, and the initialization of SupPoints displays oddly. There is also at least one syntax error (the last for loop is missing the colon). If it’s easier, you can paste your code sample on a pastebin site or a GitHub gist, where these issues won’t occur.
def main():
NUM_PTS_IN_LINE = 100
mypoint = Super_Point()
print(mypoint.red)
mypoint.randpoint()
print(mypoint.red)
SupPoints = []
# This Works
#This does not work
#Create list of 100 radomized super points
for r in range(NUM_PTS_IN_LINE):
SupPoints.append(Super_Point())
for g in SupPoints:
print("before", g.red)
g.randpoint
print("after", g.red)
main()
for g in SupPoints:
print("before", g.red)
g.randpoint
print("after", g.red)
The obvious thing here is that you do not call g.randpoint(). You just
reference the method:
g.randpoint
That’s a valid Python expression. But it doesn’t call the method
without some brackets. It just makes a reference to the method. That’s
not as pointless as you might think. g.randpoint is a callable:
# get a reference to the method
# (specificly, the method bound to the "g" object)
f = g.randpoint
... later ...
# call the method, randomises "g" now
f()
def main():
NUM_PTS_IN_LINE = 100
mypoint = Super_Point()
print(mypoint.red)
mypoint.randpoint()
print(mypoint.red)
SupPoints = []
# This Works
#This does not work
#Create list of 100 radomized super points
for r in range(NUM_PTS_IN_LINE):
SupPoints.append(Super_Point())
for g in SupPoints:
print("before", g.red)
g.randpoint
print("after", g.red)
main()