Python:“str”对象不可调用

2024-03-15

我有以下代码

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内置函数。 http://docs.python.org/2/library/functions.html#str

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python:“str”对象不可调用 的相关文章

随机推荐