Trent
Trent

Reputation: 1275

Unable to invoke/call a Python method

can't get my class variables working properly,

class World:
  def __init__(self, size):
    self.size = size
    self.grid = []
    for i in range(0,size):
        self.grid.append([])
        for j in range(0,size):
            self.grid[i].append(0)
  def Display(self):
    for row in self.grid:
        print row

TheWorld = World(int(raw_input("Input world size(integer): ")))
TheWorld.Display

The problem is, the display function doesn't do anything, i think it's not referencing self.grid properly somehow. I input the world size as 0,10,100, doesn't make a difference. Any ideas ?? Thanks

Upvotes: 0

Views: 102

Answers (4)

unni
unni

Reputation: 2991

Well that should be because you have not actually called the Display function. You have to say

TheWorld.Display()

for the function to be actually called.

Upvotes: 3

user811773
user811773

Reputation:

Add braces to call the method:

TheWorld.Display()

Upvotes: 1

warvariuc
warvariuc

Reputation: 59674

This is not VBA. I have to call the function using ():

TheWorld = World(int(raw_input("Input world size(integer): ")))
TheWorld.Display()

Upvotes: 1

Avaris
Avaris

Reputation: 36735

You are not calling the function, you are merely referencing the function object. Try:

TheWorld.Display()

Upvotes: 8

Related Questions