当我尝试将 class 字符串更改为 python 中的字节时,问题出在哪里?
Where is the problem when I try to changed the class string to bytes in python?
def write(self,vals):
for record in self:
emp_id = record.employee_name
user = self.env['res.users'].search([("email",'=',record.mail)])
if vals.get('unit_icon'):
if vals.get('unit_name'):
members = self.env['team.works'].search([('unit_name.id','=',vals.get('unit_name'))])
else:
members = self.env['team.works'].search([('unit_name.id','=',record.unit_name['id'])])
#print("---------------------------1")
#print(type(vals.get('unit_icon')))
b = bytes(vals.get('unit_icon'), 'utf-8') #This line the give the error
#print(b)
#print("---------------------------2")
for i in members:
#print("---------------------------3")
#print(type(i['unit_icon']))
#print(i['unit_icon'])
i['unit_icon'] = b
#print("---------------------------4")</pre>
大家好。我正在使用 odoo project.If 更改徽标,我想更新其他成员的徽标但是有一个 problem.Changed 徽标 class 是一个字符串。Updated logo other members logo class is bytes other member logo。我正在尝试将字符串转换为字节以实现此目的
b = bytes(vals.get('unit_icon'), 'utf-8')</pre>
After changed class 但它给了我错误“类型错误:没有字符串参数的编码”。代码有什么问题?
如果 vals.get('unit_icon') 是字符串那么 Pythonic 方式是:
b = vals.get('unit_icon').encode() # encode defaults to 'utf-8'
def write(self,vals): for record in self: emp_id = record.employee_name user = self.env['res.users'].search([("email",'=',record.mail)]) if vals.get('unit_icon'): if vals.get('unit_name'): members = self.env['team.works'].search([('unit_name.id','=',vals.get('unit_name'))]) else: members = self.env['team.works'].search([('unit_name.id','=',record.unit_name['id'])]) #print("---------------------------1") #print(type(vals.get('unit_icon'))) b = bytes(vals.get('unit_icon'), 'utf-8') #This line the give the error #print(b) #print("---------------------------2") for i in members: #print("---------------------------3") #print(type(i['unit_icon'])) #print(i['unit_icon']) i['unit_icon'] = b #print("---------------------------4")</pre>
大家好。我正在使用 odoo project.If 更改徽标,我想更新其他成员的徽标但是有一个 problem.Changed 徽标 class 是一个字符串。Updated logo other members logo class is bytes other member logo。我正在尝试将字符串转换为字节以实现此目的
b = bytes(vals.get('unit_icon'), 'utf-8')</pre>
After changed class 但它给了我错误“类型错误:没有字符串参数的编码”。代码有什么问题?
如果 vals.get('unit_icon') 是字符串那么 Pythonic 方式是:
b = vals.get('unit_icon').encode() # encode defaults to 'utf-8'