KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
How to check that the file exists? How to append a text to the file? I know how to create the file, but in this case, it overwrites all data: import io with open('text.txt', 'w', encoding='utf-8') as file: file.write('text!') In *nix I can do something like: #!/bin/sh if [ -f text.txt ] #If the file exists - append text then echo 'text' >> text.txt; #If the file doesn't exist - create it else echo 'text' > text.txt; fi;
Tags (comma-separated)
Save Edits
Cancel