Simple commands in Python for writing in a text file
- open(filename): returns a file object, you can assign the result to a variable, such as 'file'.
- file.close(): Closes the file, just like 'File -> Save' in word for example.
- file.read(): Reads the content of the file. You can assign the result to a variable.
- file.readline(): Reads just one line of a text file.
- file.truncate(): Empties the entire file, be carefull when using this on a file you wish to save.
- file.write('stuff to write here or variables with input here'): Writes the 'stuff' you typed or variable you selected to the file.
- file.seak(0): Moves the read / write location to the beginning of the file.