Python¶
Python is an easy-to-learn high-level general-purpose programming language. It is especially suitable for beginners to programming, amateurs/hobbyists, scientists, engineers.
Pros:
- Easy to learn
- High-level
- Dynamically typed
- Simple and readable syntax
- Vast ecosystem
- Large community and help sources
- Rapid prototyping
- Excellent glue language
- Many packages interface with C or other fast languages to achieve performant code
- Interoperable with many other languages
Cons:
- Very slow: About 50 times slower than C. This is not a deal-breaker though for a glue/scripting language, and for prototyping purposes.
- Low-quality packages: There are almost no imposed requirements on packages and compability between packages: Expect compatibility issues, breaking functionality across package versions, unintuitive APIs, and lacking documentation.
- Non-standardized tooling: despite the emphasis on the Pythonic way, there are hilariously many cases of competing tools, packages, and standards: see dependency management, repository structure, unit testing, to name a few.
- Dynamically typed: great for rapid prototyping, not for large frameworks.
- No built-in language support for vector and matrix operations: results in needlessly verbose code for any engineering or data science applications.
- No fluent interface: No support for chaining function calls, which is a common use case in analysis scripts and data manipulation. This results in many data science libraries resorting to the builder pattern, which forces the use of implementing subclasses just to call another function.
Short Python cheatsheets:
- https://www.pythoncheatsheet.org/
- https://quickref.me/python
Run¶
Script¶
| Action | Code | Details |
|---|---|---|
| Start Python script, wait for completion |
|
|
| Start Python script with arguments, wait for completion |
|
Environment¶
Environment variables¶
All snippets require import os. Updates to the environment are not reflected in the os.environ mapping.
| Action | Code | Details |
|---|---|---|
| Get list of all environment variables |
|
|
| Get all environment variables as dict |
|
|
| Check if environment variable exists |
|
Case-insensitive |
| Get value of environment variable, error if not found |
|
|
Try get value of environment variable, or return None
|
|
|
Try get value of environment variable, or return None
|
|
|
| Try get value of environment variable, or return default value v |
|
|
| Set / update environment variable |
|
|
| Set environment variable only if it is not yet defined |
|
|
| Delete environment variable, error if not defined |
|
|
| Delete environment variable, error if not defined |
|
|
| Try delete environment variable |
|