Python Read Binary File

During your career as a Pythonista, you will most likely find yourself required to work with binary data. See the examples outlined below to efficiently read/write to a Binary file. Preparation Before any data manipulation can occur, one (1) new library will require installation. The NumPy library supports multi-dimensional arrays and matrices in addition to … Read more

What’s the Difference Between exit(0) and exit(1) in Python?

The function calls exit(0) and exit(1) are used to reveal the status of the termination of a Python program. The call exit(0) indicates successful execution of a program whereas exit(1) indicates some issue/error occurred while executing a program. What is the Exit Code? Let’s have a look at some examples to get a clear picture … Read more

How Do I List All Files of a Directory in Python?

Problem: Given a directory. How to list all the files in the directory using Python? Video Solution  What is a directory?A directory is a unit organizational structure used to store a collection of programs and subdirectories. Sometimes as a coder you have to deal with the countless number files within different directories. Hence, it becomes … Read more

Python Version Bit – Does My Python Shell Run 32 Bit or 64 Bit Version?

To check which bit version the Python installation on your operating system supports, simply run the command “python” (without quotes) in your command line or PowerShell (Windows), terminal (Ubuntu, macOS), or shell (Linux). This will open the interactive Python mode. The first line provides information whether it’s a 32 bit or 64 bit version. Alternatively, … Read more

Python Version Anaconda

Open Terminal: On Windows, start Anaconda by searching for “Anaconda Prompt” and click the first result. On Linux and macOS, just open the terminal or shell. Then run either of the following commands, depending on what you want to do. Python Anaconda Version: To check your Python version in Anaconda, run python -V or python … Read more

Python Print Without Space

Problem Formulation Python’s print() function allows an arbitrary number of comma-separated values and prints them to the shell, separated by a single empty space character ‘ ‘. The following example shows how you pass four string values as arguments into the print() function: The resulting shell output has an added empty space character ‘ ‘ … Read more

How to Serialize a Python Dict into a String and Back?

Problem Formulation Given a Python dictionary containing lists and other data structures. You want to store the dictionary in a file or send it over the network in a more efficient form. How to serialize a Python dictionary into a string, and then deserialize the string back to a dictionary data structure? Here’s a rough … Read more

How To Execute System Commands With Python?

[toc] In this article, we will learn numerous ways to execute system commands in Python. βž₯ Problem: Given an external command that can run on your operating system, how to call the command using a Python script? βž₯ Example: Say you want to ping a remote server using your operating system’s ping commandβ€”all from within your Python program. … Read more