#!/usr/bin/python
# Filename: print_info.py
class print_info:
name=''
#define init method
def __init__(self,a):
self.name=a
def print_space(str,status):
number=33-len(str)
for i in range(1,number):
str=str+' '
str=str+status
print str
#print_ok
def print_ok(self):
self.print_space(self.name,'passed')
def print_error(self):
self.print_space(self.name,'failed')
There are two solutions:
First.add an argument representing instance in the method definition (name it self for consistency)
def print_space(self,str,status):
number=33-len(str)
for i in range(1,number):
str=str+' '
str=str+status
print str
Second.use staticmethod decorator on the method.
@staticmethod
def print_space(str,status):
number=33-len(str)
for i in range(1,number):
str=str+' '
str=str+status
print str