AttributeError:“str”对象没有属性“seek”

2024-05-19 07:06:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我是Python3的傻瓜。我广泛地寻找问题的解决方案,但是我不明白为什么方法.seek()不能工作。 我想做一个程序,把一个档案的信息复制到另一个档案的最后一个。我知道为什么我会用其他的方法。在

提前谢谢。在

from sys import argv
script, from_file, to_file=argv
print(f"Are you sure that you want to copy {from_file} to {to_file}?")
print("Ready hit RETURN to continue, CTRL-C to abort")
input()
origin_file=""
final_file=""

try:
  file1=open(from_file,'r')
  file2=open(to_file,'r+')
  file1=file1.read()

except:
  print('There is not a file')

file2.seek(0,2)
file2.write(file1)

print(final_file)

已解决:无法对字符串对象使用seek::)


Tags: to方法fromyouseek档案openfile1

热门问题