Python: 'str' 对象不可调用

标签 python string

我有以下代码

f = open('BigTestFile','w');
str = '0123456789'
for i in range(100000000):
    if i % 1000000 == 0:
        print(str(i / 1000000) + ' % done')
    f.write(str)
f.close()

当我运行它时,我得到了这个TypeError:

Traceback (most recent call last):
  File "gen_big_file.py", line 8, in <module>
        print(str(i / 1000000) + ' % done')
TypeError: 'str' object is not callable

这是为什么呢?如何修复?

最佳答案

将变量称为 str 以外的名称。 它正在跟踪 str built in function.

关于Python: 'str' 对象不可调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17963264/

相关文章:

php - 截断 UTF-8 字符串以适应 PHP 中给定的字节数

c# - 从字母数字字符串中删除字符的最快方法是什么?

java - Java中打印两个DNA字符串之间对应的数字串

python - 尝试使用 TensorBoard 时出现 AttributeError : module 'tensorboard.util' has no attribute 'PersistentOpEvaluator' ,

python - 如何解决: 'str' object has no attribute 'data_format' in keras

python - 在我的算法中实现 raw_input

python - Python赋值运算符不同于非赋值运算符

搜索字符串时python编码错误

java - 在 Java 中分解包含姓氏、名字和首字母的字符串

python - PyInstaller .exe 文件什么都不做