web123456

TypeError: xxx takes 1 positional argument but 2 were given solution

I have been debugging this exception for a long time today. I don’t test directly without the class, but I always report errors when using the class method. I checked the information and found that the main error was that my function did not add self.
The details are as follows:
1. Problem

class replace_html (object):
     def __init__(self,name=''):
         #Read oracle configuration
         conf = gcon(bv.config_dir)
         #Read SQL statements
         sql = conf.read_text(bv.xiao_duan_sql)[0]
          = conf.get_oracle_data(sql,names=name)
     def test_120_130names(self):
         #Short data summary
         #The first table of short products
         param_analy={}
     def is_persent(x):
         if type(x)!=str:
             if x<1.0:
                 x='%0.1f%%' %(x*100)
             else:
                 if (x):
                     x=''
                 elif type(x)==float:
                     x = '%0.1f' %x
                 else :
                     x =str(x)
         Return x

When running is_persent(x) always prompts:
TypeError: is_persent() takes 1 positional argument but 2 were given

2. Solution
The solution is obvious, that is, add self to the class function, and the problem is solved
The main reason is that when the class calls the inner function of the class, the self parameter will be automatically passed in; for example, if self is not written in the function, then the parameter is only x, but when the function call is passed in the parameter (self, x), so the function will report an error.