text file Flashcards

1
Q

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
2
Q

output file

A

a file containing program results

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

in Python, data or output file could be

A
  • a binary file (not readable by human)
  • a text file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

text file

A
  • a disk file containing a collection of characters
  • text file can be viewed or created using a text editor
  • can be used for input (read from) or output (write to)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

advantages of using text file as data files

A
  • entering data with a human readable data file
  • If program output is written to a file, a permanent copy will be available
  • the output file generated by one program can be used as input data to another file
  • easily created with a text editor or similar tool that can write text files
  • easy to check & edit
  • you can establish your own format
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

mode β€œr”

A

open a file for reading ( to get data from file )

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

mode β€œw”

A
  • open a file for writing ( to save data into a file )
  • if doesn’t exist, Python create a new one
  • if exist, existing contents will be deleted and replaced with a new one
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

mode β€œa”

A
  • open a file for appending data from the end of the file
  • existing contents will not be deleted
  • if file doesn’t exist, error
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

mode β€œrb”

A

opens a file for reading binary data

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

mode β€œwb”

A

opens a file for writing binary data

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

how to check for file existence

A

isfile function in the os.path module

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

read ()

A
  • read a specified number of characters
  • if not specify, read all characters

and return them as string

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

readline ()

A

read the next line

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

readlines ()

A

read all the lines into a list of strings

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

writing and reading numeric data type

A
  • convert into str data type
  • separate them with whitespace characters ( β€œ β€œ ) or /n ( in order to read the numbers back correctly )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly