首页 > 其他 > 详细

TypeError: print_space() takes exactly 2 arguments (3 given)

时间:2014-03-02 10:49:49      阅读:655      评论:0      收藏:0      [点我收藏+]

#!/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
 





TypeError: print_space() takes exactly 2 arguments (3 given),布布扣,bubuko.com

TypeError: print_space() takes exactly 2 arguments (3 given)

原文:http://blog.csdn.net/zbdba/article/details/20205843

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!