当前位置:网站首页>Typeerror: 'STR' object is not callable error reason
Typeerror: 'STR' object is not callable error reason
2022-07-25 19:29:00 【Shining umbrella】
I encountered a problem writing code today TypeError: 'str' object is not callable.
The reason for the error 1
Let me show you my code :( Code function description : Match numbers with regular expressions and +1 operation , Then replace the original number )
str='literal books=1000'
def add1(match):
val=match.group()
num=int(val)+1
return str(num)
info=re.sub(r'\d+',add1,str)
print info
#literal books=1001
Why did it go wrong ? Baidu for a while , I saw a foreign website saying
You are redefining what str()
means. str is the built-in Python name of the string type, and you
don’t want to change it.Use a different name for the local variable,
and remove the global statement.
Translation means ,str() It comes with the system , You can't define another name by yourself when using it str The variable of , It's going to conflict .
So I put the customized str The variable was changed to another name ,str1, The code passes .
This is because if I customize my name str The variable of ,str It will be recognized by the system as a string conversion function , Such a function is passed into sub In the parameters of the function ,is not callable, in other words , Is not callable . Check whether your code has similar errors ?
The reason for the error 2
stay Python in , A function is actually an object , And all functions are callable objects . A class instance can also become a callable object , Only need to implement a special way __call__().
therefore , When an error is reported XXX is not callable When , It is likely that you are calling a variable or object that cannot be called , The specific performance is that you call the function 、 Wrong way of variable .
Link to the original text :https://blog.csdn.net/lifelegendc/article/details/55051374
边栏推荐
- Network design and planning of a company
- Wechat campus maintenance application applet graduation design finished product of applet completion work (8) graduation design thesis template
- University of California | feasible confrontation robust reinforcement learning for unspecified environments
- IP地址的概念
- 微信小程序开发之WXSS模板样式与WXS脚本语言
- 小程序毕设作品之微信校园维修报修小程序毕业设计成品(3)后台功能
- Selenium运行慢 - 通过设置selenium加载策略加快运行速度
- 英诚医院内部网络规划与设计
- Wechat campus maintenance and repair applet graduation design finished product (7) Interim inspection report
- [reading notes] deep learning Chapter 1: Introduction
猜你喜欢

微信小程序10-微搭模板

Why learn service grid istio

Dynamic implementation of wechat applet 27 progress bar and static construction of search box and hot search list
平衡二叉树

Code sharing of social chat platform developed by dating website (III)

Network design and planning of a company

Actual combat of MySQL database design project of online mall system
![[wp]ctfshow-web入门信息搜集](/img/22/c2e5cca918800dda9df27272eb9871.png)
[wp]ctfshow-web入门信息搜集

解决Win10账户没有了管理员权限

Swift 基础 Codable(JSONEncoder JSONDecoder)的使用
随机推荐
国内常见php的CMS建站系统情况分析
Talk about 11 tips for interface performance optimization
The second "future Cup" knowledge map championship was officially launched
Introduction of this course (Introduction to machine learning)
Global configuration and page configuration of wechat applet development
哈希无向图可视化
An idea of solving div adapting to screen
Amrita Institute of Engineering | reinforcement active learning method for optimizing sampling in terms extraction of emotional analysis
[wp]ctfshow-web入门-爆破
手机端触摸图片slider轮播插件photoswipe.js
Network packet multi-layer transmission demonstration
小程序毕设作品之微信校园维修报修小程序毕业设计成品(1)开发概要
Scala foundation [set 01]
小程序毕设作品之微信校园维修报修小程序毕业设计成品(5)任务书
Day7:有序二叉树(二叉搜索树)
微信小程序 28 热搜榜的完善①
How to be a self disciplined person?
虹科分享|如何解决勒索软件安全漏洞
【阅读笔记】《深度学习》第一章:引言
给容器添加3d效果的副标题