Files
AutomateTheBoringStuffWithP…/practice_questions/ch08/README.md
kerogen-pezy 5eeca42044 Finished Ch08
2017-06-20 11:34:01 +08:00

37 lines
1.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Chapter 8 Reading and Writing Files
> Q: 1. What is a relative path relative to?
The current working directory.
> Q: 2. What does an absolute path start with?
The root folder. such as `/` or `C:\`
> Q: 3. What do the os.getcwd() and os.chdir() functions do?
Get current path, and change the current working directory.
> Q: 4. What are the . and .. folders?
`.` is current folder, `..` is the parent folder.
> Q: 5. In C:\bacon\eggs\spam.txt, which part is the dir name, and which part is the base name?
`C:\bacon\eggs` is the dir name, `spam.txt` is the base name.
> Q: 6. What are the three “mode” arguments that can be passed to the open() function?
`r`, `w`, `a`.
> Q: 7. What happens if an existing file is opened in write mode?
Existing file will be erased and completely overwritten.
> Q: 8. What is the difference between the read() and readlines() methods?
`read()` returns the file's entire contents as a single string. `readlines()` returns a list of each lines.
> Q: 9. What data structure does a shelf value resemble?
dictionary.