See match
All posts by
match
In python the equivalent to switch case in other languages is match: break There is no break in Python for match. break is only used for loops. If you want to achieve being able to break from a match case early you can use an exception trick like this:
pass -placeholder for future code
You can use Pass where Python requries some code but you don’t have any for that place currently, e.g.
typedef enum in Python
In C you might do this to create an automatically numbered from 0 list of values for example: In python you can do the same it with the Enum class Using Enum values
Working With Files
We use pathlib and forward slashes so that the Path() function can be used to automatically convert backslash to forward slash on Linux systems. Does file exist? Getting file name elements Delete file
Read XML
Read XML value from a XML string Read XML value from an XML file In node present? Is item empty? Item is empty if it has no text and no child elements Parse XML values from an XML file Read attribute value in a sub node
Sanitising & encoding strings
URL Encode and Decode
HTTP POST
Post a file Post a file from binary data I.e, POST without needing to save your data to a file first Post file and other data fields Getting the data with PHP
DELETE queries
Delete example
Key Value arrays
In python you use Dictionaries for this