Skip to main content


Showing posts from April, 2022

Screen Capture Using Python

Nowadays, screen capturing is one of the common tasks which most of us are doing in our day-to-day routine and there are instances where in we need to automate this task. In this article, I'll explain you about how can we automate screen capturing using Python. To get started, first of all we need to grab all the required packages and install them. Required packages To automate screenshot capturing, we need to install a package named pyautogui and this can be installed using pip as shown below: pip install pyautogui     Import packages Once required packages are installed, we need to import them into our code. Here we need to import two packages - one for screenshot capturing and another one is for timer as we need to capture our screen after certain seconds of our application launch. Here is the code: import pyautogui import time Implementation  Now we have all the packages imported, we can go ahead and make a call to required function. We will start by calling a function screen

Effective ways to sort Python iterables

The traditional way to sort iterables is by using loops, like for loop or while loop. As part of this article, I am not going to cover this traditional way, rather I will be focusing on a better way to implement sorting. And that better way is by using sorted function . Let's take a look at below list holding some numbers: numbers = [ 2 , 3 , 6 , 4 , 9 , 1 ] Python Copy To sort this list, we just need to call a function as shown below:  numbers = sorted ( numbers ) Python Copy To sort this list in reverse order, we need to pass an additional parameter: numbers = sorted ( numbers , reverse = True ) Python Copy Apart from this simple case, we can also handle some complex scenarios wherein we have a list containing key-value pairs as shown: studentDetails = [ { “Name” : “Nick” , “Marks” : 23 } , { “Name” : “Roy” , “Marks” : 2 } , { “Name” : “Honey” , “Marks” : 45 } ] Python Copy Now, say you want to sort studentDetails based on Marks. So, the only code you n

Create Word Art From An Image Using Python

If you are Python developer then you may be fully convinced that we can do very cool things using Python in very easy way. Today I’m going to show you a very beautiful usage of Python, in which we will see how we can generate a word art of any given image. You can pick an image of your pet, you can pick an image of a natural scenery, you can pick an image of human, basically you can pick anything as your image.  Once the image is selected, it is just the matter of few lines of Python code. Package To generate word art we need to install a package named pywhatkit . If you are using pip to install your Python packages, then here is the syntax: pip install pywhatkit Code Once the package is installed, you need to import the package and call the function named image_to_ascii_art(…) . This function will take two parameters — first one is the image file path and second parameter is the name for output file. Here are the two lines of code: import pywhatkit pywhatkit.image_to_ascii_art(“Wolf.p