Saving current Python file contents without filename -


so need able copy across current file contents (first 20 characters) file without using filename changed @ time. how go this? far have code uses file-name:

h="this a virus!" i="this not copied" print("you have copied target file!")  infile = open ("assignment1.py", 'r') filestr = infile.read() appendfile = filestr[0:20]   l = list() f = open('target.py', 'r') line in f.readlines():     l.append(line) l.insert(0,appendfile) f.close()  fi = open('target.py', 'w') line in range(len(l)):     fi.write(l[line])  fi.close() 

u can use listdir folder files:

from os import listdir  files = listdir('path_to_folder')  one_file in file:     open(one_file, 'r') f:         data = f.read(20)     open(one_file, 'w') f:         full_data = f.read() + data         f.write(full_data) 

Comments