plik = open('plik.txt') # open file (default open function)
plik = open('plik.txt', w) # open/clear and write in new/existing file
plik = open('plik.txt', x) # only if file is not existing yet
# operation in file
plik.write('lubie owoce') # will write in the buffer. After commed plik.close() or plik.flash() it will appear in the file
plik.flash # send data to file
plik.writelines('Kot ma Ale')
plik.writelines(function) # will work with generator for the file
# plik.writelines can add LIST to the file for example:
Lets play with creation of files
List_cust = ['MCX', 'NGO','Afgha_tree']
plik = open('Customers.txt', 'w')
plik.writelines(List_cust)
plik.close()
# with give assurance that the file will be closed even if ERROR will appear in the middle. It is commonly use when you work with file
with open('Customers.txt') as plik:
print(plik.readlines()) # I can add more operations below that line
>>>['MCXNGOAfgha_tree']
No comments:
Post a Comment