Skip to content

Instantly share code, notes, and snippets.

@AD0791
Last active October 17, 2020 19:40
Show Gist options
  • Save AD0791/20408ae4ffd70cbb9c83947108011f74 to your computer and use it in GitHub Desktop.
Save AD0791/20408ae4ffd70cbb9c83947108011f74 to your computer and use it in GitHub Desktop.
python for developers notes 2

Python programming for developpers


We are moving from the Basic.md

import Basic

Python Standard Libraries

  1. Python Standard Library, status:watch
  • Working with paths: from pathlib import Path, Path class helps us create path object, combination is possible Path() / Path("ecommerce/file.py"), We get a lot of useful methods
  • Working directories: we are still working with the Path class, we can make dir and remove dir, rename dir, Path().iterdir() is a generator, Pathlib is a must read again
  • working with files: access the file with the pathlib module with all his files, we can work with files, Path().read_text() or .write_text() or write_bytes() instead of open(), make a copy with the module shutil, time module to work with time object
  • Working with zip files: from Zipfile import Zipfile, with as syntax is better, we still the pathlib module to access the files with a path object, you can build a script to read or write
  • Working with csv files: import csv, combine with the with open("ok.csv","r or w") as file: <action>

pathlib, shutil

The documentation is avalaible on python.org

This module offers classes representing filesystem paths with semantics appropriate for different operating systems. Path classes are divided between pure paths, which provide purely computational operations without I/O, and concrete paths, which inherit from pure paths but also provide I/O operations.

shutil

documentation is on python.org

  • pythoncore/standardtopic/files/file.py is a perfect example of copying around some file content using several python built-in libraries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment