commit message from python script
This commit is contained in:
17
Lehrer/pythonkurs/Mittwoch/writefile
Executable file
17
Lehrer/pythonkurs/Mittwoch/writefile
Executable file
@@ -0,0 +1,17 @@
|
||||
#! /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)
|
||||
Reference in New Issue
Block a user