When working with Python virtual environment, there is a need to run a stocktake of what is installed inside the environment. Pip Freeze The following pip command will show which packages are installed inside a Python virtual environment. Before running the command, go ahead and activate the virtual environment using the following command (the environment…… Continue reading Check Which Packages Installed Inside a Python Virtual Env
Author: admin
Install Flask on Ubuntu and Python Virtual Env
In this post, we will install the Flask web framework on Ubuntu Linux 20.04 inside a Python virtual environment. If you don’t have a Python virtual environment, let’s create one. First, we need to install Python virtual environment tools using the following command. sudo apt-get install python3-venv Now that we have the virtual environment installed…… Continue reading Install Flask on Ubuntu and Python Virtual Env
Count How Many Items Are in a Python List
When working with lists in Python something we need to know how many items are in the list before proceeding, and this is what we will show today. Lists A Python list (also known as an array) holds items (numbers or strings) in a structure that allows us to access them by the order they…… Continue reading Count How Many Items Are in a Python List
Create a List With Python
This post will show how to create a list object with Python and print it out as a whole or using a for loop statement. Lists A list in Python allows us to store multiple items and later on retrieve them for processing. Lists are structured and hold the information in order. Create and print…… Continue reading Create a List With Python
Create a Simple If Statement With Python
This post will show how to create a very simple if statement using Python and compare values. If Statement The whole idea behind an if statement is to compare values and build a logic that action tasks based on the results of the statement. Creating an if statement with Python is not complicated as you…… Continue reading Create a Simple If Statement With Python
Create a Function With Python 3
Writing code is all about efficiency and adoption of DRY (don’t repeat yourself), and functions are essential components to these concepts. With Python, we can create functions that take variables and functions that doesn’t take variables, as you will see shortly. In the following code example, we will create two functions. The first takes two…… Continue reading Create a Function With Python 3
Check if a File Exist With Python
In this post, we will use Python to check if a file exists on the operating system and print the result. OS Path To read file paths and check if a file exists on the system, we need to use the os.path module, and therefore we need to import into the code (as shown below).…… Continue reading Check if a File Exist With Python
Get File Size With Python
In this post, we will learn how to get a file size with Python using a build-in function. Using Python build-in function, we can measure a file size using Python len function. Code In the below code example, I’m opening and reading a file and using the len function to measure the size of the…… Continue reading Get File Size With Python
Write Content to a File With Python
In our previous blog post, we have learned how to read files with Python, and now we will write content into a file with Python. Writing In the following code example, we start with opening a file called file1.txt into a file object called fileobject. We also use a variable called content to save a…… Continue reading Write Content to a File With Python
How to Read Files With Python
This blog post will show how to read files with Python built-in functions. Files Working with files and content is something that Python knows how to handle very easily and allow developers to be very creative. Options In the following examples, I have a code the I am passing a file as an argument (example…… Continue reading How to Read Files With Python