我这里有这个简单的代码遇到问题输出到文件
import os
path = (raw_input("Enter dir: "))
f = open('script_list.log', 'w')
for dirpath, dirname, filenames in os.walk(path):
for filename in [f for f in filenames]:
f.write(str(filename) + "\n")
print os.path.join(dirpath, filename)
当我运行它,我得到以下
Enter dir: scripts
Traceback (most recent call last):
File "C:\Documents and Settings\CRichards\My Documents\My Dropbox\this_code.py", line 8, in <module>
f.write(str(filename) + "\n")
AttributeError: 'str' object has no attribute 'write'
我知道这一定是简单的东西,我只是”没有看到它。
是的,我改变了F =开放和f.write登录=开放, log.write解决了它。新鲜的眼睛和一切。非常感谢 – geekcomputers 2012-02-15 12:46:26