Chapter 7: Text File Flashcards
1
Q
How to permanently store data created in a program?
A
saving it in a data file
2
Q
What is a Data File(input file)
A
a file containing input data for a program
3
Q
Advantages of Using Text File as data files
A
- Entering data with human readable data dile
- if output is written to a file, a permanent copy will be available
- output generated can be used as input data to another file
- easy to check & edit
- you can establish your own format
4
Q
Opening a File
A
fileVariable = open(filename.txt, mode)
5
Q
modes for opening files:
A
- r = open a file for reading
- w = opens a file for writing. if file already exists, existing contents r deleted and replaced
- a = opens a file for appending data
- rb = reading binary data
- wb = writing binary data
6
Q
Writing data to a file:
A
open file for output
outfile = open(“PrimeMinisters.txt”, “w”)
outfile.write(“gddjjd”)
outfile.write(“hdhfkeje”)
outfile.close()