Pliki

  • obiekt iterowalny
  • open(filename, mode) -> zwraca obiekt pliku
  • r read
  • r+ read i write
  • w write
  • b binary dodawany do r/w np rb
  • a append

In [ ]:
import os
f = open("temp.txt", 'w')
f.write("ala ma kota \n ala ma kota\n a")
f.close()

f = open("temp.txt", 'r')
for line in f:
    print(line)
f.close()

os.remove("temp.txt")

In [ ]:
import os
with open("temp.txt", 'w') as f:
    f.write("ala ma kota \n ala ma kota\n a")

with open("temp.txt", 'r') as f:
    print(f.readlines())

os.remove("temp.txt")

In [ ]:
import os
with open("temp.txt", 'a') as f:
    pass

os.remove("temp.txt")

In [ ]:
import os
def touch(path):
    with open(path, 'a') as f:
        os.utime(path, None)

path = "temp.txt"
touch(path)
os.remove(path)