使用seek()和read()方法从索引列表中检索隐藏代码。你知道吗
这是代码行为的示例:
>>>getCode("Da Vinci Code.txt", [4, 992, -26, 1242, 332])
'sofia'
def getCode(filename, indexes):
f=open(filename,'w')
str=''
for x in indexes:
f.seek(x)
str=str+f.read(x)
return str
f.close()
运行代码时出错:
Traceback (most recent call last):
File "Code", line 7, in getCode
File "/base/data/home/apps/s~pyschools2/888.418298200144529338/gaefile.py", line 223, in seek
raise IOError("Invalid argument")
IOError: Invalid argument
函数
file.seek()
和file.read()
似乎不支持否定参数。你知道吗你可以把代码改成这个
只使用正数。您需要更改索引才能使此版本的代码正常工作。你知道吗
相关问题 更多 >
编程相关推荐