当前位置:网站首页>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
边栏推荐
- 网络数据包多层传输演示
- leetcode刷题:动态规划07(不同的二叉搜索树)
- Clip can also do segmentation tasks? The University of Gottingen proposed a model clipseg that uses text and image prompt and can do three segmentation tasks at the same time, squeezing out the clip a
- Wechat campus maintenance and repair applet graduation design finished product (5) assignment of applet completion work
- Hongmeng - Damiao computing Sketchpad - VIDEO
- ERROR: role “admin“ cannot be dropped because some objects depend on itDETAIL:
- Talk about 15 tips of SQL optimization
- Hongmeng - Damiao computing Sketchpad - Introduction
- How to be a self disciplined person?
- [reading notes] deep learning Chapter 1: Introduction
猜你喜欢

六轴传感器使用学习记录

前夕 - 0day威胁情报

Talk about 15 tips of SQL optimization

Eve - 0day Threat Intelligence

微信小程序10-微搭模板

Clip can also do segmentation tasks? The University of Gottingen proposed a model clipseg that uses text and image prompt and can do three segmentation tasks at the same time, squeezing out the clip a

Pymoo learning (5): convergence analysis

小程序毕设作品之微信校园维修报修小程序毕业设计成品(2)小程序功能

手机端触摸图片slider轮播插件photoswipe.js

安全基础6 ---漏洞复现
随机推荐
小程序毕设作品之微信校园维修报修小程序毕业设计成品(5)任务书
鸿蒙-大喵计算画板-视频
Is there a "fingerprint" in the structure of AAAI 2022 | Gan? Generating network structure from forged image traceability
[server data recovery] a data recovery case of a brand ProLiant server raid paralysis, database file loss, and database file backup damage
房地产行业大洗牌
Common misunderstandings caused by a time reporting assistant of Blue Bridge Cup basic questions
Swift 基础 Codable(JSONEncoder JSONDecoder)的使用
Wechat campus maintenance and repair applet graduation design finished product (7) Interim inspection report
哈希无向图可视化
485 current acquisition module dam-8041
Code sharing of social chat platform developed by dating website (III)
QIIME2得到PICRUSt2结果后如何分析
Empire CMS whole station | mobile number /qq lianghao mall source code | suitable for mobile terminal
How many lines of code is appropriate for a function? Clean Code
一个函数中写多少行代码比较合适呢? 代码整洁之道
FPGA based 1080p 60Hz bt1120 interface debugging process record
Grid layout frequently asked interview questions
binarySearch基础二分查找
[reading notes] deep learning Chapter 1: Introduction
微信小程序开发之网络数据请求