There are several Python libraries available for time tracking in Python. We will start by highlighting the commonly used packages for time tracking – datetime and time.
Continue readingCategory Archives: Python
Remove Characters From String Using Regex and Python
This article discusses removing the special characters from a Python string using the re module. We will cover all cases you might think of – remove punctuations, white spaces, numbers, and the first letter of every word in the string, among other cases.
Continue readingConvert 2d List to String in Python
A 2-dimensional (2D) list is simply a list of lists (lists within a list). Here are some examples of 2D lists in Python.
Continue readingConvert Bytes to Float Numbers in Python
This article discusses how to use struct and Numpy packages in Python to convert bytes to floats and vice-versa. Before we do that, however, let’s briefly discuss the difference between bytes and floating-point numbers.
Continue readingSplit Input by Space in Python
There are two key functions we need to use here: input(<prompt>) and str.split(<char>).
Continue readingRedirect Stdout to a File in Python
Python uses the following two file objects on the sys library as output streams:
- sys.stdout – used for output of print() function and the prompt in input() function,
- sys.stderr – is an output stream for Python’s prompts (like the help() function), errors, and exceptions.
Check if an Argument in a Function Is Passed in Python
Consider the following Python function:
1 2 3 4 5 |
def func1(val1, val2, val3): return val1 * val2 + val3 # Calling the function. result = func1(3, 4, 6) |
Random Delays in Web Scraping in Python
Adding random delays between queries is a great way to avoid getting blocked while running scripts in Python. This technique can be used to ensure that the script is not making too many requests in a short period and thus, preventing it from being blocked by the server.
Continue readingSuppress Console Output in Python
Python interpreter uses the following three file objects on the sys library for standard input, output, and errors (exceptions):
Continue readingPrint Memory Address of Python Variable
Every time a Python object is stored in memory, it is assigned an integer value that references its address. The address is used to distinguish between different objects present in memory.
Continue reading