Python: Cannot concatenate str and NoneType objects

后端 未结 5 1206
一向
一向 2020-12-20 23:39
sql = \"\"\"
        INSERT INTO [SCHOOLINFO] 
        VALUES(
            \'\"\"\" + self.accountNo + \"\"\"\', 
            \'\"\"\" + self.altName + \"\"\"\',
            


        
5条回答
  •  天命终不由人
    2020-12-21 00:08

    All these answers so far focus not on your problem but on what is right to do. Yes, yes - bind variables is better and safer. And yes, using % for formatting is faster and likely better.

    But on your question what gives you that error - it must be that one of the values is None at some point, there is no other explanation. Just put a debug print in front of that, something like:

    for v in 'accountNo altName address1 address2 city state zipCode phone1 phone2 fax contactName contactEmail prize_id shipping chairTempPass studentCount'.split():
        if getattr(self, v) is None:
            print 'PANIC: %s is None' % v
    

    I bet it will print something at some point ;-)

提交回复
热议问题