not supported between instances of 'SafeText' and 'int' 问题出现以及解决
1、今天更新完代码,突然间报了这个错误:'<' not supported between instances of 'SafeText' and 'int'
2、主要代码如下,其中是最后一行报错的:
if value is not None and value != '':# 将要格式化的数值转成字符串对象if type(value) == 'str':value = valueval = Decimal(value)else:val = valuevalue = str(value)# 处理负数flag = '-' if val < 0 else ''
意思就是SafeText的不能和int做小于判断,断点调试,发现传过来的value类型是一个如下图的东西:
3、使用下面代码输入其类型:
print(type(value))
发现类型为<class 'django.utils.safestring.SafeText'>,安全文本类型,因此代码底下的if条件不通过,走到else里了,而val直接赋值为value了,所以后面判断时就会报上面的错误
4、修改代码如下:
if value is not None and value != '':# 将要格式化的数值转成字符串对象if type(value) == 'str':value = valueval = Decimal(value)else:val = Decimal(value)value = str(value)# 处理负数flag = '-' if val < 0 else ''
5、这样就不会报错了,暂时解决办法,以上内容仅供学习参考,谢谢!
not supported between instances of 'SafeText' and 'int' 问题出现以及解决相关推荐
- 成功解决极其刁钻bug之TypeError: ‘<=‘ not supported between instances of ‘list‘ and ‘int‘
成功解决极其刁钻bug之TypeError: '<=' not supported between instances of 'list' and 'int' 目录 解决问题 解决思路 解决方法 ...
- 提示错误“'=' not supported between instances of 'range' and 'int'”
在学习<Designing Machine Learning Systems with Python>(中文名<机器学习系统设计--python语言实现>)一书中,第三章第二节 ...
- 【已解决】TypeError: ‘<‘ not supported between instances of ‘str‘ and ‘int‘_Python系列学习笔记
TypeError: '<' not supported between instances of 'str' and 'int' 翻译:str类型无法与int类型比较 解决:将<两侧类型 ...
- 成功解决TypeError: ‘<‘ not supported between instances of ‘str‘ and ‘int‘
成功解决TypeError: '<' not supported between instances of 'str' and 'int' 目录 解决问题 解决思路 解决方法 解决问题 Type ...
- 执行Python提示《not supported between instances of str and int》
1 n = input() 2 if n>=100:print(int(n)/10) 3 else:print(int(n)*10) 报错内容: Traceback (most recent c ...
- ‘<’ not supported between instances of ‘str’ and ‘int’
'<' not supported between instances of 'str' and 'int' python 中 字符串 和 整形 进行比较之后 出现的报错信息. python 中 ...
- TypeError: not supported between instances of str and int【python3】
python3报错:TypeError: '>' not supported between instances of 'str' and 'int' **报错原因:**int类型没有转换为st ...
- TypeError: not supported between instances of 'treeNode' and 'treeNode'
问题 TypeError: '<' not supported between instances of 'treeNode' and 'treeNode' 原因: python3 和pytho ...
- TypeError: ‘<‘ not supported between instances of ‘Example‘ and ‘Example‘解决办法
最近在用torchtext时碰到一些问题,在博文参考这篇博文中给出了方案,但没有完全解决问题,依然报错. 在对BucketIterator.splits了解后发现其中的参数sort_with_batc ...
最新文章
- java 异常类_Java异常处理
- 计算机本科重邮调剂重庆其他二本,重庆多少分能上二本大学,重庆二本大学最低分数线...
- 整理就知识,你会在里面发现新的东西
- OpenGL shader interpolation 着色器插值的实例
- 再观手游市场新风口-二次元游戏
- 905. 按奇偶排序数组
- 可视化ASP.Net Core Web API健康检查
- OSSemPost()--发出一个信号量
- 接口说明_接口说明_实时语音识别_智能语音交互-阿里云
- 人工智能时代!Python跃升编程语言第一名!
- 阿里巴巴CTO程立:双11的再进化
- Android 状态栏适配
- win10 win11 创建共享文件夹 mac 苹果电脑共享 无internet 安全,你的电脑只能访问本地网络中的其它设备 共享文件夹会导致本地电脑无法上网,
- 【剑指 Offe】剑指 Offer 18. 删除链表的节点
- 一年级计算机课画画用什么,一年级孩子学画画该学哪种
- 大众点评数据分析报告
- cf Educational Codeforces Round 54 C. Meme Problem
- 计算机网考里操作题发邮件,计算机网考操作题题型.doc
- java 线程池超时_线程池中如何控制超时时间?
- 用友U8+ V16.0 V15.1 V15.0 V13.0 V12.5 12.1 12.0 11.1 11.0注册