[root@mysql1 pshell]# cat ex41-1.py
#!/usr/bin/env Python
#-*-coding:utf-8-*-
class thething(object):
def __init__(self):
self.number=0
def some_function(self):
print "i got called."
def add_me_up(self,more):
self.number+=more
return self.number
#two different things
a=thething()
b=thething()
a.some_function()
b.some_function()
print a.add_me_up(20)
print b.add_me_up(30)
print a.number
print b.number
#study this. this is how you pass a variable
#from one class to another. you will need this.
class themultiplier(object):
def __init__(self,base):
self.base=base
def do_it(self,m):
return m*self.base
x=themultiplier(a.number)
print x.do_it(b.number)
[root@mysql1 pshell]# python ex41-1.py
i got called.
i got called.
20
30
20
30
600
#!/usr/bin/env Python
#-*-coding:utf-8-*-
class thething(object):
def __init__(self):
self.number=0
def some_function(self):
print "i got called."
def add_me_up(self,more):
self.number+=more
return self.number
#two different things
a=thething()
b=thething()
a.some_function()
b.some_function()
print a.add_me_up(20)
print b.add_me_up(30)
print a.number
print b.number
#study this. this is how you pass a variable
#from one class to another. you will need this.
class themultiplier(object):
def __init__(self,base):
self.base=base
def do_it(self,m):
return m*self.base
x=themultiplier(a.number)
print x.do_it(b.number)
[root@mysql1 pshell]# python ex41-1.py
i got called.
i got called.
20
30
20
30
600