Python
Python, created by Guido van Rossum and first released in 1991, is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with its notable use of significant indentation.
The language draws developer’s eye sight due to
- Readability and Simplicity: Python’s clean syntax and emphasis on readability make it easy to learn and use, reducing the cost of program maintenance.
- Dynamic Typing: Python is dynamically typed, which means you don’t have to declare the type of variables, making it more flexible and faster to develop with.
- Extensive Standard Library: Python comes with a large standard library that supports many common programming tasks, from connecting to web servers to reading and modifying files.
- Cross-platform Compatibility: Python is available for all major operating systems like Windows, macOS, and Linux, allowing developers to write code that runs on multiple platforms.
- Vibrant Community and Ecosystem: Python has a large and active community that contributes to a vast ecosystem of third-party packages and libraries, such as those found in the Python Package Index (PyPI).
- Support for Multiple Paradigms: Python supports multiple programming paradigms, including procedural, object-oriented, and functional programming.
- Extensibility: Python can be extended with modules written in other languages like C or C++, allowing for performance-critical code to be optimized.
- Automatic Memory Management: Python manages memory automatically via a garbage collector, freeing developers from manual memory management.
Python continues to be one of the most popular programming languages in the world, with a growing community and a constant stream of new libraries and frameworks.
Web Site
Tools
- Pip
- Jupyter Notebook
- PyCharm
- VS Code
Basic
Use of future
For Type Hint in python, before 3.10+, the coding is not easy to understand, especialy when using the syntax "SomeType".
Using from __future__ import annotations
In Python 3.7–3.9, you can enable postponed evaluation of type annotations by importing annotations from the __future__ module. This means all type hints are stored as strings and only evaluated when needed, allowing you to:
- Use forward references (refer to classes/types before they are defined)
- Use modern type hint syntax (like
|for unions in Python 3.10+) - Avoid issues with circular imports in type hints
This feature is enabled by default in Python 3.10, but was reverted in 3.11+ (see PEP 563 and PEP 649 for details). In 3.7–3.9, you must import it explicitly.
Example: Forward Reference in Type Hints
|
|
Notes:
- Tools like mypy and IDEs will interpret type hints as strings when this feature is enabled.
- For even older Python versions, use string-based type hints:
def set_next(self, next_node: 'Node') -> 'Node': ... - See PEP 563 and PEP 649 for more details.
group n items in a list to sub list
|
|
pad array into dictionary
|
|
Generate string of markdown table
|
|
Use python to decode json from stdin
|
|
A command line tools called jq is also workable, but require extra installation for the tool.
Read/Write data from clipboard
In python read / write data from clipboard, pyperclip is required.
|
|
Extract XML data
In python extracting xml data, requires package lxml.
|
|
Read XML from clipboard and load into lxml for processing
|
|
Execute OS commands and capture output (subprocess)
Use subprocess to run shell/OS commands from Python and read their standard output:
|
|