file = open('new.pdf', 'wb') for line in open('code.txt', 'rb').readlines(): file.write(line) file.close()