text file Flashcards
1
Q
data file (input file)
A
a file containing input data for a program
2
Q
output file
A
a file containing program results
3
Q
in Python, data or output file could be
A
- a binary file (not readable by human)
- a text file
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)
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
6
Q
mode βrβ
A
open a file for reading ( to get data from file )
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
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
9
Q
mode βrbβ
A
opens a file for reading binary data
10
Q
mode βwbβ
A
opens a file for writing binary data
11
Q
how to check for file existence
A
isfile function in the os.path module
12
Q
read ()
A
- read a specified number of characters
- if not specify, read all characters
and return them as string
13
Q
readline ()
A
read the next line
14
Q
readlines ()
A
read all the lines into a list of strings
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 )