Don’t Re-Invent the Snake

Don’t Re-Invent the Snake

There are common situations that you may encounter while working with files. Most of these cases can be handled using other modules. Two common file types you may need to work with are .csv and .jsonReal Python has already put together some great articles on how to handle these:

Additionally, there are built-in libraries out there that you can use to help you:

  • wave: read and write WAV files (audio)
  • aifc: read and write AIFF and AIFC files (audio)
  • sunau: read and write Sun AU files
  • tarfile: read and write tar archive files
  • zipfile: work with ZIP archives
  • configparser: easily create and parse configuration files
  • xml.etree.ElementTree: create or read XML based files
  • msilib: read and write Microsoft Installer files
  • plistlib: generate and parse Mac OS X .plist files

There are plenty more out there. Additionally there are even more third party tools available on PyPI. Some popular ones are the following:

  • PyPDF2: PDF toolkit
  • xlwings: read and write Excel files
  • Pillow: image reading and manipulation