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

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -