我正在通过学习Python艰难的方式工作,并坚持练习16的额外功劳.我正在尝试阅读我使用主要练习创建的文件16.我写的代码如下:
# pylint: disable-msg=C0103
""" This script reads and prints a file set from the argv """
from sys import argv
filename = argv
txt = open(filename)
print txt.read()
Run Code Online (Sandbox Code Playgroud)
我想读的文件是:
Derp Derp
Reading this file
Will it work?
Run Code Online (Sandbox Code Playgroud)
我收到错误:TypeError:强制转换为Unicode:需要字符串或缓冲区,找到列表但不确定我的文件是如何列表而不是字符串.