impfile = open('путь')
textfile = impfile.read()
print(textfile)
impfilecopy = open('путь', 'w')
impfilecopy.write(textfile)
print(impfilecopy)
Почему то не копирует информацию из первого файла во второй.
Stack Overflow на русском — это сайт вопросов и ответов для программистов. Присоединяйтесь! Регистрация займёт не больше минуты.
Присоединиться к сообществуЕсли нужно скопировать полностью файл, то можно воспользоваться модулем shutil.
import shutil
shutil.copy2(r'C:\main.txt', r'D:\filename.txt')
In [12]: with open('file1.txt') as first, open('file2.txt', 'w') as second:
...: data = first.read()
...: second.write(data)
impfile = open('t.txt', 'r')
textfile = impfile.read()
impfile.close()
print(textfile)
impfilecopy = open('a.txt', 'w')
impfilecopy.write(textfile)
impfilecopy.close()
file1 = open('file1.txt', 'r')
textfile1 = file1.read()
file2 = open('file2.txt', 'w')
file2.write(textfile1)
print(textfile1)
file1.close()
file2.close()
file2 = open('file2.txt', 'r')
textfile2 = file2.read()
print(textfile2)
file2.close()