Jar*_*red 4 python file-io typeerror
当我运行此代码时:
tickers = re.findall(r'Process Name: (\w+)', s)
file = open("C:\Documents and Settings\jppavan\My Documents\My Dropbox\Python Scripts\Processes\GoodProcesses.txt","w")
file.write(tickers)
file.close()
Run Code Online (Sandbox Code Playgroud)
它返回常见错误:
TypeError:期望一个字符缓冲区对象
有任何想法吗?
小智 18
findall()作为名称指示返回Python 列表而不是字符串/缓冲区.
你不能写一个列表到文件句柄 - 这应该如何工作?
你能指望什么?
file.write(str(tickers))
Run Code Online (Sandbox Code Playgroud)
对于列表的字符串表示?
要么
file.write(', '.join(tickers))
Run Code Online (Sandbox Code Playgroud)
对于列表项的逗号分隔串联?
无论如何...... write(..)需要字符串或缓冲区.
除此之外:不要调用你的文件句柄'文件'.
file()是一种内置方法.
| 归档时间: |
|
| 查看次数: |
27652 次 |
| 最近记录: |