Python Notes and Examples

Files and Directories

Import io for open.

Import os for chdir, getcwd, listdir, mkdir, remove, rename, walk, etc.

Import os.path for basename, dirname, exists, isdir, getmtime, etc.

Files

and the file is automatically closed when we leave the with block.

Directory Walking

Note that while walking the dirs, we do not change our cwd.