File Handling in Python
File Handling in Python
Writing in a file
OPENFILE "filename.txt" FOR WRITE
//When opening a file to write, all the data already existing in the file is OVERWRITTEN
WRITEFILE "filename.txt" , Value
// The next command of WRITEFILE would be writen on next line of the file
CLOSEFILE "filename.txt"
Appending a file
OPENFILE "filename.txt" FOR APPEND
//When data will be written now, the file would be continued after the last line
WRITEFILE "filename.txt" , Value
// The next command of WRITEFILE would be writen on next line of the file
CLOSEFILE "filename.txt"
Reading a file:
OPENFILE "filename.txt" FOR READ
READFILE "filename.txt" , Variable
// The value in the line (which is identified by the number of times this is being run) is stored
in the variable
CLOSEFILE "filename.txt"