File creation in Python -
i have been reviewing the tutorial file management in python 3 doesn't mention how create file if 1 doesn't exist. how can that?
just open file in write mode:
f = open('filetowrite.txt', 'w')
note clobber existing file. safest approach use append mode:
f = open('filetowrite.txt', 'a')
as mentioned in this answer, it's better use with
statement ensure file closed when have finished it.
Comments
Post a Comment