相关疑难解决方法(0)

Python:'str'对象不可调用

我有以下代码

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()
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我得到了这个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
Run Code Online (Sandbox Code Playgroud)

这是为什么?怎么修?

python string

1
推荐指数
2
解决办法
2510
查看次数

标签 统计

python ×1

string ×1