Files

18 lines
582 B
Python
Executable File

#! /usr/bin/env python3
def write_into_file(path, lines):
# Mode r=read, w=write, a=append
with open(path, 'w') as outfile:
# Python2.x: outfile.write(string + '\n')
# v2 und v3: outfile.writelines(map(lambda s: s+'\n', lines))
# outfile.writelines(f'{l}\n' for l in lines)
# outfile.writelines(l+'\n' for l in lines)
for line in lines:
print(line, file=outfile)
lines = []
lines.append("Das ist eine Zeile einfacher Text")
lines.append("Zur Sicherheit noch eine weitere Zeile")
write_into_file("/tmp/test.txt", lines)