Lesson 11 Flashcards

1
Q

Limitations to imputing data into Python

A

It would be very tedious to use terminal screen arguments or input() prompts for large amounts of data.
Data is often transferred as files (a self contained collection of data)

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

To open a file in python use

A

open() function which takes the filename as a string and an optional mode argument.

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

Mode “r”

A

Read default- open for reading, error if file does not exist

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

Mode “a”

A

Append open for appending, creates file if it does not exist. File pointer starts at the end of the file

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

Mode “w”

A

Write- open for writing created file if it does not exist. Deletes all existing data in file

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

Mode “x”

A

Create file and open for writing. File Exists Error if file exists.

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

Mode “r+”

A

Read/write open file for reading and writing

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

Two necessary things about opening a file

A

1) the file needs to be in the same directory as your current directory in the terminal, or it needs to contain the path to the file.
In this course, we are only learning how to handle text files

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

read(<opt.>)</opt.>

A

Returns all the text in the file. Optional argument used to specify how many characters to read. Move the file pointer to the next unread character. File must be opened in “r “ mode

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

Readline()

A

Returns all the text up to and including the next new line character (\n) move the file to the pointer to the start of the next line. File must be opened in “r” mode.

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

Close()

A

Close the file, which you should always do to avoid python, locking the file or not writing all the data to the file

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

Write(<str>)</str>

A

Write a string to the file. File must be opened in “a” or “w” mode

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