class - How to understand python classes? -
hello i'm learning python, first language. i'm trying figure out how classes work. have small code , can't work after week of searching. thank helping me.
also i'm trying figure out getattr , super do. read on documentation not easy me understand. english not native language , little difficult understand sometimes.if can explain 2 things or if know website explains in simple way thank it.
here code:
import sys class map(object): dicti = {'stuff': stuff(), 'more_stuff': more_stuff() } class stuff: def stuff(self): print "did work?" next = raw_input("type next: ") if next == "next": return 'more_stuff' else: print "what? lets try again." return 'stuff' class morestuff: def more_stuff(self): print "ok" next = raw_input('type next: ') if next == "next": return 'stuff' else: print "bye." sys.exit(0) class newclass(map): def __init__(self, themap): self.themap = themap def continu(self): next = self.themap while true: print "----" room = next() a_test = newclass('stuff') a_test.continu()
you passing string 'stuff'
newclass
, becoming self.themap
later assigning next = self.themap
, next
reference string 'stuff'
.
room = next()
fail because can't call string
Comments
Post a Comment