Python 3 latest code crumbs

Your first program

Your first program

Dec 10, 2021 by erik

This is the interactive version of the example in the Python.land tutorial here....

Read YAML file with multiple documents with Python

Read YAML file with multiple documents with Python

Dec 10, 2021 by erik

PyYAML can read YAML files that contain multiple documents by using the yaml.safe_load_all() function. Note that the file needs to be opened as long as you're reading documents from the YAML, so you have to do your processing within the...

How to read YAML with Python and PyYAML

How to read YAML with Python and PyYAML

Dec 10, 2021 by erik

There are multiple Python packages that can parse YAML data. However, PyYAML is the most prevalent and also the most complete implementation for parsing YAML. PyYAML is not part of the standard Python library, meaning you need to install it...

Using docstrings to document your code

Using docstrings to document your code

Dec 8, 2021 by erik

A docstring is a string that occurs as the first statement in a module, function, class, or method definition. Such a docstring becomes the __doc__ special attribute of that object. You can read docstrings with the help() function....

Encoding JSON with json.dumps

Encoding JSON with json.dumps

Dec 7, 2021 by erik

Encoding JSON data with Python's json.dumps is just as easy as decoding. Use json.dumps (short for ‘dump to string') to convert a Python object consisting of dictionaries, lists, and other native types into a string. To learn more about JSON...

Read JSON with json.loads

Read JSON with json.loads

Dec 7, 2021 by erik

Parsing a string of JSON data, also called decoding JSON, is as simple as using json.loads(…). Loads is short for load string. It converts: - objects to dictionaries - arrays to lists, - booleans, integers, floats, and strings are recognized...