Please enable JavaScript.
Coggle requires JavaScript to display documents.
8 Reading and Writing Files ((The File Reading/Writing Process . 180,…
8
Reading and Writing Files
Files and File Paths 173
Backslash on Windows and Forward Slash on OS X and Linux 174
The Current Working Directory 175
Absolute vs. Relative Paths 175
Creating New Folders with os.makedirs() 176
The File Reading/Writing Process . 180
Opening Files with the open() Function . 181
Reading the Contents of Files . 182
Writing to Files 183
Saving Variables with the shelve Module . 184
Saving Variables with the pprint.pformat() Function . 185
The os.path Module . 177
Handling Absolute and Relative Paths . 177
Finding File Sizes and Folder Contents 179
Checking Path Validity 180
Project: Generating Random Quiz Files 186
Step 1: Store the Quiz Data in a Dictionary . . . . . . . . . . . . . . . . . . . . . . . . 187
Step 2: Create the Quiz File and Shuffle the Question Order . 188
Step 3: Create the Answer Options 189
Step 4: Write Content to the Quiz and Answer Key Files 189
Project: Multiclipboard . 191
Step 1: Comments and Shelf Setup . 192
Step 2: Save Clipboard Content with a Keyword . 192
Step 3: List Keywords and Load a Keyword’s Content . 193
Practice Projects 194
Extending the Multiclipboard . 194
Summary . 194
Practice Questions . 194