|
发表于 2024-8-11 12:24:23
|
显示全部楼层
本楼为最佳答案
本帖最后由 jackz007 于 2024-8-11 12:47 编辑
看看这个楼主就明白了:
- Python 3.12.1 (tags/v3.12.1:2305ca5, Dec 7 2023, 22:03:25) [MSC v.1937 64 bit (AMD64)] on win32
- Type "help", "copyright", "credits" or "license()" for more information.
- >>>fishc=r'''I
- love
- FishC'''
- >>>print(fishc) # 一开始,print() 函数可以被正常调用
- I
- love
- FishC
- >>>print = fishc # print 被赋值,成为一个字符串对象,函数名称 print 被污染
- >>>print(fishc) # 从此以后,print() 函数无法被正常调用
- Traceback (most recent call last):
- File "<pyshell#5>", line 1, in <module>
- print(fishc)
- TypeError: 'str' object is not callable # 错误信息是不是和楼主遭遇到的一模一样?
- >>>del print # 没关系,只要使用这条命令即可使被污染了名称的函数恢复正常调用
- >>>print(fishc) # print() 函数已经可以被正常调用了
- I
- love
- FishC
复制代码 |
|