Skip to main content

Posts

5 Unique and Useful Python modules.

Motive           There are different types of modules in python which not everyone knows so we thought of introducing them to you guys. Let's start! Note: This is not a tutorial of how to use these but is to show that these modules also exist and if you want to know more you can visit there own page and if you want us to explain leave a comment below. Links to there page are also given below. Hope you found something useful. 1.Wikipedia          Yes, there is a module called Wikipedia in python, you can easily install Wikipedia by pip install wikipedia . We cannot rely on this module for advanced use. It was designed for ease of use and simplicity.  Learn More Here .  Here is a simple example: import wikipedia wikiPython = wikipedia.summary("Python", sentences=2) print(wikiPython)           One big disadvantage is that it works only if the interne...
Recent posts

Digital Clock | Python | Pygame

  Motive            Just to keep this the way I make other projects on my website. Just ignore this and jump right into the project. Oh and here's a preview of what we are going to make. The Project          We will be using pygame to create our Digital Clock, I believe all of you have installed pygame, if not just open the command prompt and type pip install pygame and hit enter. Learn more about pygame here  https://www.pygame.org/docs/ . Feel free to skip to the end to get the full code.           Okay back to the project, first, let's make a basic pygame window. So import pygame, initialize pygame, set an icon, make a screen like a rectangle then set its caption or whatever you call it, make a while loop to make it run till the exit button is pressed, and update the pygame display. Looks like a lot but these are nece...

Python Find IP Address | Python socket Library

  Motive          I don't even know what to write in the motive section, but as I usually write something in the motive section. This would help you find your IP address.  The Project         First import socket, and by the way it's pre-installed so, no pip install needed. The create a variable called hostname then we will get the hostname with sockets.gethostname(). Then create another variable called ipAddress then get our IP address with that hostname, socket.gethostbyname(hostname). Then just print ipAddress by print(ipAddress). That's it! The Full Code import socket hostname = socket.gethostname() ipAddress = socket.gethostbyname(hostname) print(ipAddress)         If you have any doubts or errors in the program feel free to comment down below and I will respond as early as possible. And if I have made any mistake please feel free to ...

Never Lose a Game of Chess | Python Chess Hack

Motive            I lost every game that I played chess with my friends. So why not cheat, even though  it was not the best option, I had to somehow prove that I was not dumb and can even win against them. Since they play online with me, I had a better chance to cheat so I thought of creating an ai to play against them but it was not that easy so I started surfing through the internet to find a better way. Then I found stockfish it was a chess engine that generates the best move for us. So I used it as my AI. Again, luck was with me I was able to find a module called chess in python that helped me a lot and now my work was really very easy. At last, I created the program and won the games against them but they had figured out that I was cheating and my friends started mocking at me. Then I understood that I was wrong and I shouldn't have cheated and started working hard for it and now I literally can win matches with ...

Python Text to Speech | Python pyttsx3 Library

Motive          Like always just showing you about a new library and how to use it properly. Hope that this would be helpful for you guys!   The Project         We will be using the pyttsx3 library for text to speech, so before we move on with the project we need to install the library. As always we need to open our terminal and type pip install pyttsx3 and wait for it to complete the installation in case you get any error related to win32 just install pywin32 by pip install pywin32. pip install pyttsx3 Now import pyttsx3 and initialize it with sapi5. sapi5 is a Speech API developed by Microsoft.  import pyttsx3 engine = pyttsx3.init('sapi5')           We have two voices preinstalled they are David and Zira so if we need to access those voices we first have to define them and set it as the engine property. You can even try print...

Get COVID19 status with Python | Get Current Covid Cases | Python Library covid

Motive           I just want to show you guys about the new library for  getting the number of people with COVID and those who have recovered from the whole world or from a specific country. I wish this could be useful for you guys. The Project             As I said t his Library can be used for getting the number of people with COVID and those who have recovered from the whole world or from a specific country. So let's begin! As always installing the library is the first thing we should do. So open up ur terminal and type pip install covid  and hit enter and let it download. According to there documentation, it says that the library works on python 3.6 or above. pip install covid           Let's find the things that we can do with the library before that open your preferred IDE and import the library with from covid impo...

Shutdown Computer with Python | Shutdown Prank .

Motive          Pranking friends is really fun. So, I thought of sharing an idea for pranking your friends with python. Or if you have any problem with your power button you could use it. The Project          It's really very simple no pip installs and just two lines of code and we are done. First let's import a module called os, again no need for any pip it's pre-installed in python. Import the module and give the command for shutdown: import os os.system('shutdown /s /t 0')           Here shutdown is the command for shutdown we can even use sleep or restart,  /s tells  that the shutdown should happen in that PC and /t tells about the time and 0 is the seconds that are left for the shutdown to happen it can be from 0 to 315360000 i.e 5 years.           But even a person who knows to read English can understand the code so we have to hide it somewhere either in c...

Find MAC Address with Python

Motive          This is just as a fun project which you can even use for other backend projects, who don't like python and programing with it so let's dive through the modules in python. The Project          Let's start by importing the module which is pre-installed, UUID. You can learn more  here . Now, let's import the module:  import uuid           Now let's create a variable called mac and then get the MAC address and then format it into a string from a 48-bit number and the add a ':', colon after two digits: mac = ':'.join(['{:02x}'.format((uuid.getnode()>>x) & 0xff) for x in range (0,8*6,8)][::-1]) Now let's print the MAC address after converting it with uppercase letters: print('MAC Address:',mac.upper()) So that's it we have got our MAC address with just 4 lines of code. Full Code import uuid mac = ':'.join(['{:02x}'.format((uuid.getnode()>>x) & 0xff) ...

Python QR Code Decoder | QR Code to text

Motive           In our last blog, we created a QR code generated with python so why not a decoder to decode the QRcode without scanning it.  Project             Before starting to make a project lets install the necessary modules for this project,  pyxbar  and  pillow . Motive           In our last blog, we created a QR code generated with python so why not a decoder to decode the QRcode without scanning it.  Project             Before starting to make a project lets install the necessary modules for this project,  pyxbar  and  pillow . pip install pyzbar pip install pillow           Open your cmd and type those codes separately to install  pyzbar  and  pillow and you can learn more about  pyzbar  here ...

Python QR Code Generator

Motive          QR Codes are seen everywhere, even tho it's not really useful we could encrypt some data in them or we could even use it for other backend purposes. Let's begin! Project          Before starting to make a project lets install the necessary modules for this project, pyqrcode and pypng . Even tho we are not importing pypng directly the module pyqrcode imports it and if we try running without installing pypng we will get an error so install both of them. pip install pyqrcode pip install pypng     Open your cmd and type those codes separately to install pyqrcode and pypng and you can learn more about pyqrcode  here and pypng  here . Let's start by importing the necessary modules for our project: import os,pyqrcode      It's not necessary to import os. But if you want to open the QR code after it's created by the pro...

Python | if __name__ == '__main__' Explained | Python Tutorial

Motive          When I was a beginner I had this big doubt while watching tutorials on YouTube. I saw people using this  if  __name__ ==  '__main__'  even though it was not required. So, I thought of learning the special variables in python. So I thought that this will be useful for you guys also. Let's Learn          First I created a folder named special variables and then created a new python file called mainProgram and tried printing  __name__ in this file like this: print(__name__)  I got the result as  __main__ in the python shell. Then I tried printing its type like so: print(type(__name__))           Now I got  <class 'str'>  in the python shell. So that's why we use inverted commas for __main__ ( since it is a string).         Now let's create a new python file called importedProgram, in the same folder and import t...

Face Detection with Open CV | Unsupervised learning in Python

Motive                  Machine Learning is not that easy to lean in python and YouTube tutorials cannot rely heavily so I taught of making a model and explain to you guys how machine learning works. We will not be making the rules for the model instead we will take a pre-trained model for our use. Training a model takes time and we need a lot of data so we will take the easier path for now.  The Project          The only library that we need is OpenCV, if you have not installed it then pip install it in your terminal,  pip install opencv-python .  You can learn more  here . Now open your preferred ide and import opencv, while coding we use cv2 for opencv: # import opencv import cv2           Now as I told above we will use a pre-trained model for this use so download it from  here . Now let's mention it in the code and ensure that the XML file is in th...

Python Password Generator

Motive          If you have read my other blogs you might have understood that I watch a lot of YouTube videos, Today I came across a video the made a Password generator. But that doesn't work as expected to work. All it does it shuffles all letters and number and the pick some out according to the length we gave at the beginning of the program. But here comes the problem it does not always have all numbers and special characters and some times it's just even though we have given all the necessary characters. So I taught about an alternative. The Project         All we need is to import is a module called string and  random. Which are pre-installed in python so no pip install needed: import string import random         String is a module which gives access to all alphabets, uppercase and lowercase. Numbers and Special Characters. Even though we could write all those, it is a bit easier to do it this way. ...

Linear Search | Python | Finding a number from a list

Motive          I am a guy who watches a lot of YouTube videos, there I saw a video that teaches a Linear search in python so I taught to try it myself and make it easier for you to understand. Let's see how it's done.   The Project         First let's make a list of numbers and name the list as list . Then let's make a function called searchFor which takes one parameter called number . list = [1,2,3,4,5,6] def searchfor(number):    Then: def searchfor(number): index = 0 indexValue = list[index] Here,we create two variables called index and set it to 0 and indexValue to the number at the index in the list(indexValue = list[index]). After that: def searchfor(number): index = 0 indexValue = list[index] while number != indexValue: index += 1 indexValue = list[index] We run a while loop in which if number  (parameter) is not equal to the indexValue, we add one to ind...

Fibonacci Sequence Algorithm in Python

Motive     To get a job as a programmer you need to pass the coding interviews in which certain questions/algorithms are asked to be solved.       The Project    What is the Fibonacci Sequence?          The Fibonacci Numbers are a series of numbers in which each number is the sum of the proceedings numbers for example 1,1,2,3,5,8,13 etc. Learn more  Here .         1. We are going to create a function that takes the n th number i.e F1=1, F2=1, F3=2, F4=3, F5=5, F6=8, F7=13 etc. In F4=3, 4 is the nth number and in F6=8, 6 is the nth number. But before that, we will make a list of the Fibonacci numbers and we can access them with its index. Let's begin, paste this code into your python ide: a=1 list=[0,1] while True: fib = list[a-1] + list[a] a+=1 list.append(fib) print(list) Run the code for about 2 sec and then press ctrl+c you will get something like this: First, we make a var...