Python 3 latest code crumbs
Convert YAML to JSON using Python
Feb 26, 2022 by erik
If you need to convert YAML to JSON, you can simply parse the YAML as we did above. In the next step, you can use the JSON module to convert the object to JSON. In this example, we open a...
Writing YAML to a file with Python
Feb 26, 2022 by erik
Although most will only read YAML as a configuration file, it can be very handy to write YAML as well. In the following example, we'll: * Create a list with names as we did before * Save the names to...
Python's Finally block In Try Except
Feb 20, 2022 by erik
The finally
block is executed regardless of whether an exception occurs or not. Finally blocks are useful, for example, when you want to close a file or a network connection regardless of what happens. After all, you want to clean...
Swap two variables in Python without using a third
Feb 15, 2022 by erik
With this neat little trick, you can swap two Python variables without using a third variable. Source: python.land blog...
Python class example
Feb 12, 2022 by erik
This is an example of a Python class. This class represents a car. It could be part of a game, for example, in which you have multiple cars running around. This example is part of the [Python objects and classes...
Python Hello World
Feb 11, 2022 by erik
This is a typical Hello World example in Python. It's part of the free and complete Python Tutorial for beginners at python.land....