Close metodu

close metody öň açylan faýly ulag serişdelerini boşatmak üçin ýapýar. Metod hiç zat gaýtarmaz. Metodyň parametrinde hiç zat görkezmeýäris.

Sintaksis

pythonfaýl.close()

Mysal

Geliň file.txt faýlyny açalyň, onuň mazmunyny okalyň, soň bolsa ony ýapalyň:

pythonres = open('file.txt', 'r')
print(res.read())
res.close()

Ýerine ýetirilen kodyň netijesi:

pythontekst

Şeýle-de görüň

  • faýly açýan open
    funksiýasy
  • faýly okýan read
    metodu
  • faýlyň birinji setirini okýan readline
    metodu
  • faýlyň ähli setirlerini okýan readlines
    metodu
  • faýla setir ýazýan write
    metodu