woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
You major problem is that __init__() uses double underlines prefix and postfix.
Also, remember that the module name and its file name are case sensitive!
Here is an example:
# save module as tank.py (file name is case sensitive!)
class Tank (object):
def __init__(self, name):
self.name = name
self.alive = True
self.ammo = 5
self.armor = 60
# test the module
if __name__ == '__main__':
mytank = Tank("Bob")
print mytank.name, mytank.armor # Bob 60
Your program should import the modules like this:
# module was saved as tank.py (case sensitive)
import tank
mytank = tank.Tank("Bob")
print mytank.name # Bob
Please make your thread title more specific, instead of "Python Problem" use "Problem with Python Class"
sneekula
Nearly a Posting Maven
2,427 posts since Oct 2006
Reputation Points: 961
Solved Threads: 212
You did not fix the misnamed __init__() function in your class!
These are double underlines front and back!
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417