Chapter : Two : Organizing the code

EXAMPLE 2.1 Page no : 12

In [2]:
#import EmcArray # EmcArray.py
#import iostream # The rest of the EmcArray.cc file 

EXAMPLE 2.2 page no : 13

In [2]:
 

class X :
    def __init__(self):
        pass    #self.aM = A()
    
    def returnA(self):
        pass    #return self.aM
        
    def withAParameter(self,a):
        pass    #self.aM = a

EXAMPLE 2.3 page no :14

In [3]:
class Y :
    def __init__(self):
        pass    #self.bM = B()
    
    def returnBPtr(self):
        pass    #return self.aM
        
    def withAParameter(self,b):
        pass    #self.bM = a

EXAMPLE 2.4 page no : 15

In [4]:
def module_exists(module_name):
    try:
        __import__(module_name)
    except ImportError:
        return False
    else:
        return True

EXAMPLE 2.5 page no : 15

In [5]:
def cStr(cpM):
    return cpM

EXAMPLE 2.6 page no : 17

In [6]:
def max_(x,y):
    if x > y:
        return x
    return y

def function(i,j):
    m = max_(i,j) # must instantiate max(int,int)
    print m

function(5,10)    
    
10

EXAMPLE 2.7 page no : 17

In [7]:
class EmcQueue:
    def __init__(self):
        pass
     
    def insert(self,t):
        pass

q = EmcQueue()
q.insert(42);

EXAMPLE 2.8 page no : 18

In [8]:
class EmcQueue:
    pass
In [ ]: