Step 1
From inside? Skip to Step 2 ssh [email protected] OR USE VPN Step 2 ssh -l uniqname flux-login.arc-ts.umich.edu Step 3 1. Quick dirty first glance
You just need a class template for example: -------------------------------- class MyStuff: x = 0 def add(self): self.x = self.x + 2 def pr(self): print self.x -------------------------------- Then you can call stuff1 = MyStuff() stuff1.pr() stuff1.add() stuff1.pr() 2. What is missing behind the scene? In Python, constructor and destructor is OPTIONAL. Full version: -------------------------------- class MyStuff: x = 0 def __init__(self): print "explicitly yelling you at your ear: instance is created" def add(self): self.x = self.x + 2 def pr(self): print self.x def __del__(self): print "yelling you that instance is deleted! (in python, only destructed at the end of the very end of program" -------------------------------- So the above explains the definition of object life-cycle 3. How to pass parameter to constructor? -------------------------------- class party: x = 0 def __init__(self,first_val,second_val): self.x = first_val*second_val print number,' = number' def add(self): self.x = self.x + 1 def pr(self): print self.x -------------------------------- j = party(1,2) 4. How to do inheritance? -------------------------------- class party: x = 0 def __init__(self,first_val,second_val): self.x = first_val*second_val print number,' = number' def add(self): self.x = self.x + 1 def pr(self): print self.x -------------------------------- class subparty(party): y = 0 jj = subparty(3,1) print jj.x print jj.y So subparty is the child class of party |
AuthorShaowu Pan Archives
December 2017
Categories
All
|