AtBS 8: Reading and Writing Files Flashcards

1
Q

What does cwd stand for?

A

Current Working Directory

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

How to return the file path for the current working directory in the interactive shell?

A

os.getcwd()

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

How to change the current working directory in the interactive shell?

A

os.chdir( NEW FILE PATH)

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

How to create a new folder?

Example

A

os.makedirs (FILEPATH)

import os

os.makedirs(‘C:\delicious\walnut\waffles’)

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

How to open a file example?

A

helloFile = open (‘C:\TestFolder\HelloWorld.txt’)

type hello file on the next window

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

How to read a file example?

A

helloContent = helloFile.read()

type helloContent in on next line

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

How to read a file by separate lines?

A

helloContent = helloFile .readlines()

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

How to write to a file?

A

When you open a file specify write with a “w” after the text file you want to open

ex.
baconFile = open (‘bacon.txt.’,’w’)

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

How to append to a file?

A

When you open a file specify append with a “a” after the text file you want to open

ex.

baconFile = open (‘bacon.txt’,’a’)

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

How to save variables in Python?

A

Use the shelve module.

pg 184

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

Difference between absolute and relative paths to files?

A

Absolute always begins with the root folder

Relative path only begins with the current working directory

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