Month: February 2021

Python memoryview() — Tame That Strange Beast!

The Python memoryview(arg) function returns a memoryview object of the given bytes or bytearray argument. This exposes the argument’s internal data (buffers) to help you access the data without intermediate copying. Syntax: memoryview(object) Arguments object Bytes or Bytearray object for which the memoryview should be returned Return Value memoryview Returns memoryview of the object. Python …

Python memoryview() — Tame That Strange Beast! Read More »

Python hex() Function — Not a Magic Trick

Python’s built-in hex(integer) function takes one integer argument and returns a hexadecimal string with prefix “0x”. If you call hex(x) on a non-integer x, it must define the __index__() method that returns an integer associated to x. Otherwise, it’ll throw a TypeError: object cannot be interpreted as an integer. Argument integer An integer value or …

Python hex() Function — Not a Magic Trick Read More »

How to Access Environment Variable Values in Python?

Problem Formulation: Say, you set an environment variable and you want to access it in your Python script. How to get the value of the environment variable? Background: Environment variables are external to the Python environment.ย  They describe the operating system environment we are using. The applications installed use this information to complete specific tasks …

How to Access Environment Variable Values in Python? Read More »

NumPy arange(): A Simple Illustrated Guide

The np.arange() function appears in 21% of the 35 million Github repositories that use the NumPy library! This illustrated tutorial shows you the ins and outs of the NumPy arange function. So let’s get started! What’s the NumPy Arange Function? The np.arange([start,] stop[, step]) function creates a new NumPy array with evenly-spaced integers between start …

NumPy arange(): A Simple Illustrated Guide Read More »