setattr(self, 'res%j' % j, res)
报错,
ValueError: unsupported format character 'j' (0x6a) at index 4
出现原因分析:
出现这种错误一般是在Python中写其他语言的代码,
%在字符串中作为格式化字符串的关键字,当其后为诸如n、c、s时进行正常转义
解决办法(不太对):
- 使用%%,即表示非关键字的%(推荐);
- 使用%,有些情况下适用。
修改1,
setattr(self, 'res%%j' % j, res)
TypeError: not all arguments converted during string formatting
修改2,
setattr(self, 'res%j' % j, res)
ValueError: unsupported format character 'j' (0x6a) at index 5
修改3,
setattr(self, 'res%dj' % j, res)
成功
python - ValueError: unsupported format character while forming strings - Stack Overflow
How to fix Python ValueError: unsupported format character ‘ ‘ (0x20) at index 3 – TechOverflow



