python - TypeError: 'str' object is not callable. Even though there is nothing called 'str' -


There are many other exact questions before I start but none of the answers are enough for my problem class / Function log.info ('foo') runs once with no problems but for the second time it is said that this error is found TypeError: 'str' is not an object corner

I came to know that there is a problem like me, but I have other strokes that I mean Tested with Dh.

My code: Import import tracebacks from Import import accounts * Class logging: DF information (self, log): self.info = '0 [94m] 'Self.rs =' \ 033 [0m 'print self.info,' info: ', self Def def (self, log): self.warn = '0 [93m' self.rs = '\ 033 [0m' print self Warning, 'Warning:', self.log, self. Def is important (self, log): self.critical = '\ 033 [9 self =' \ 033 [0m 'print self critical,' serious: ', log, self RF read_accounts (): Open ('accounts.py') for F: i, calculate in l (f): pass I + = 1 account = {} while i> 0: ac = globals () ['account_% s'% i] index = ac.find (':') uname = ac [0: index] password = ac [index 1: lane (ac)] accounts [uname] = Password i - = 1 log.info ('Username Loaded! Username Loaded:') Print Accounts DEF Main (): log.info ('Using LCK account with file ...' ) Try: excluding read_accounts (): Traceback.print_exc () log.critical ('Account can not be read! Make sure the format is correct!') Sys.exit () If __name__ == '__main__': log = Logging () main ()

its bonfire Yes, I know there is a logging module in Python but I wanted to do my own work!

Thanks in advance!

The problem is that your logging class wires the methods of all frequencies Definition:

  class logging: def information (self, log): self.info = '0 [[94m' # self.info function is no longer self.rs = ' \ 033 [0m 'print self.info,' info: ', self.rs]   

The first time you call log.info This inf calls O function. The second time, this string tries to call '\ 033 [94m]' ].

Simply use a different name for that frequency variable in all your methods - or do not create one example variable on each and every time you are defining the method: < Pre> class logging: df information (self, log): info_prefix = '\ 033 [94m' # do not conflict self.rs = '\ 033 [0m' print info_prefix, 'info:', self.rs < / Code>

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -