tituscat
tituscat

Reputation: 43

AttributeError: 'str' object has no attribute 'seek'

I’m a noob in python 3. I’ve looked extensively for the solution of my problem but I couldn’t understand why the method .seek() doesn't work. I want to do a program that copy the information of one archive to the final of another archive. I know that I could do with appending or other methods but, in fact, what intrigue me it's why the attributeerror happen in this program.

Thanks in advance.

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)

Resolved: I can't use seek with string object.:):)

Upvotes: 0

Views: 7925

Answers (1)

Zheka Koval
Zheka Koval

Reputation: 535

final_file=file2.read() <---- return string...

String object in Python don't have seek function. Probably you try seek file. You had open two file file1 and file2. Probably you try seek file2. Just try file2.seek(0,2)

Upvotes: 2

Related Questions