How-to articles, tricks, and solutions about PYTHON
How do I determine the size of an object in Python?
You can use the sys.getsizeof() function to determine the size of an object in bytes.
What are the differences between the urllib, urllib2, urllib3 and requests module?
urllib, urllib2, and urllib3 are all Python standard library modules for handling URLs.
How do I use a decimal step value for range()?
You can use the numpy library's arange() function to specify a decimal step value for the range.
How to print a date in a regular format?
In Python, you can use the datetime module to work with dates and times.
How to extract numbers from a string in Python?
In Python, you can use regular expressions to extract numbers from a string.
How do I remove duplicates from a list, while preserving order?
There are several ways to remove duplicates from a list while preserving order.
Parsing boolean values with argparse
Here is an example of how to parse boolean values with argparse in Python:
How to check if type of a variable is string?
You can use the type() function in Python to check the type of a variable.
Peak detection in a 2D array
Here is an example of a Python function that can be used to detect peaks in a 2D array:
What is __pycache__?
__pycache__ is a directory that is created by the Python interpreter when it imports a module.
How to get an absolute file path in Python
You can use the os.path.abspath() function to get the absolute file path of a file in Python.
How can I make a Python script standalone executable to run without ANY dependency?
One way to make a Python script standalone executable is by using the package pyinstaller.
Traverse a list in reverse order in Python
You can use the reversed() function to iterate through a list in reverse order.
What is the naming convention in Python for variable and function?
In Python, variable and function names should be lowercase, with words separated by underscores.
How do I remove the first item from a list?
You can use the list method pop(index) to remove the first item in a list.
How to POST JSON data with Python Requests?
You can use the requests library in Python to send a POST request with JSON data.