Chapter 7: Text File Flashcards

1
Q

How to permanently store data created in a program?

A

saving it in a data file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a Data File(input file)

A

a file containing input data for a program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Advantages of Using Text File as data files

A
  1. Entering data with human readable data dile
  2. if output is written to a file, a permanent copy will be available
  3. output generated can be used as input data to another file
  4. easy to check & edit
  5. you can establish your own format
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Opening a File

A

fileVariable = open(filename.txt, mode)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

modes for opening files:

A
  1. r = open a file for reading
  2. w = opens a file for writing. if file already exists, existing contents r deleted and replaced
  3. a = opens a file for appending data
  4. rb = reading binary data
  5. wb = writing binary data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly