Found 10784 Articles for Python

Timer objects in Python

AmitDiwan
Updated on 12-Aug-2022 12:15:19

3K+ Views

In Python, Timer is a subclass of Thread class. Calling the start() method, the timer starts. Timer objects are used to create some actions which are bounded by the time period. Using timer object create some threads that carries out some actions. The Timer is stopped using the cancel() method. How to create a Timer object Following is how you can create a Timer object in Python − threading.Timer(interval, function, args = None, kwargs = None) Starting a Timer The timer.start() is used for start the timer. Here’s an example − Example import threading # All the text displays ... Read More

Python program to find N largest elements from a list

AmitDiwan
Updated on 11-Aug-2022 12:41:41

1K+ Views

In this example, we will see how to find the N largest elements from a List. The list is the most versatile datatype available in Python, which can be written as a list of comma-separated values (items) between square brackets. Important thing about a list is that the items in a list need not be of the same type Let’s say the following is the input list − [25, 18, 29, 87, 45, 67, 98, 5, 59] The following is the output displaying the N largest element from the list. Here, N = 3 − [98, 87, 67] ... Read More

Python program to convert time from 12 hour to 24 hour format

AmitDiwan
Updated on 11-Aug-2022 11:11:01

4K+ Views

In this article, we will learn how to convert time from 12 to 24 hours format. Let’s say we have the following input date in 12-hour format − 10:25:30 PM The following is the output in 24-hour format − 22:25:30 Convert current time from 12 hour to 24 hour format To convert time from 12 hour to 24 hour format, here’s the code − Example import datetime def timeconvert(str1): if str1[-2:] == "AM" and str1[:2] == "12": return "00" + str1[2:-2] elif str1[-2:] == "AM": return str1[:-2] elif str1[-2:] == "PM" and str1[:2] == "12": return str1[:-2] ... Read More

Play a video in reverse mode using Python OpenCv

karthikeya Boyini
Updated on 26-Jun-2020 09:29:05

493 Views

The full form of OpenCv is Open Source Computer Vision, using this library we can perform different operations on images, videos.Application areas of OpenCVFacial recognition systemMotion trackingArtificial neural networkDeep neural networkVideo streaming etc.For installing on Windows we can use this command linepip install opencv-pythonFor Linux −sudo apt-get install python-opencvTo complete our task we have to follow some steps −Step 1: We import OpenCv library named cv2. Step 2: Take a video as input data. Step 3: First we break the video into a number of frames and store all these frames in a list. Step 4: When we are getting ... Read More

Read and Write to an excel file using Python openpyxl module

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

5K+ Views

Python provides openpyxl module for operating with Excel files. How to create Excel files, how to write, read etc. can be implemented by this module. For installing openpyxl module, we can write this command in command prompt pip install openpyxl If we want to give a sheet title name Example code import openpyxl my_wb = openpyxl.Workbook() my_sheet = my_wb.active my_sheet_title = my_sheet.title print("My sheet title: " + my_sheet_title) Output My sheet title:Sheet To change Title Name Example code import openpyxl my_wb = openpyxl.Workbook() my_sheet = my_wb.active my_sheet.title = "My New Sheet" print("sheet name ... Read More

Python Tools for Web scraping

Samual Sam
Updated on 26-Jun-2020 09:29:53

244 Views

In computer science Web scraping means extracting data from websites. Using this technique transform the unstructured data on the web into structured data.Most common web Scraping tools In Python3 are −Urllib2RequestsBeautifulSoupLxmlSeleniumMechanicalSoupUrllib2 − This tool is pre-installed with Python. This module is used for extracting the URL's. Using urlopen () function fetching the URL's using different protocols (FTP, HTTPetc.).Example codefrom urllib.request import urlopen my_html = urlopen("https://www.tutorialspoint.com/") print(my_html.read())Outputb'\r \r

Generating random strings until a given string is generated using Python

Samual Sam
Updated on 26-Jun-2020 09:33:53

437 Views

Given a string, our task is to generate some strings using the random combination of characters, special characters, numbers etc.ExampleInput PP Output AK AK . . . . .AlgorithmStep 1: Input a string. Step2: Here we store all possible combination of lowercase, uppercase and special characters in a variable. Step3: Use two loops and use random function. From this, we can get all the possible combinations of characters, symbols. Step4: At the end display same string which is same as an input string and it matches each random string with given input string. Step5: If both index values are same ... Read More

A single neuron neural network in Python

karthikeya Boyini
Updated on 26-Jun-2020 09:35:04

620 Views

Neural networks are very important core of deep learning; it has many practical applications in many different areas. Now a days these networks are used for image classification, speech recognition, object detection etc.Let’s do understand what is this and how does it work?This network has different components. They are as follows −An input layer, xAn arbitrary amount of hidden layersAn output layer, ŷA set of weights and biases between each layer which is defined by W and bNext is a choice of activation function for each hidden layer, σ.In this diagram 2-layer Neural Network is presented (the input layer is ... Read More

Decimal Functions in Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

12K+ Views

In Python, there is a module called Decimal, which is used to do some decimal floating point related tasks. This module provides correctly-rounded floating point arithmetic. To use it at first we need to import it the Decimal standard library module. import decimal In this section we will see some important functions of the Decimal module. The square root function sqrt() and Exponent function exp() The sqrt() method is used to calculate the square root of a given decimal type object. And the exp() method returns the e^x value for the given x as Decimal number. Example Code ... Read More

Create a Website Alarm Using Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

385 Views

In this section we will see how to create the website alarm system using Python. Problem Statement Open a website URL on the browser by taking a website URL and time. When the system time reaches the specified time, the webpage will be opened. We can store different web pages in our bookmark sections. Sometimes we need to open some web pages every day on a specific time to do some work. For that purpose, we can set this type of website alarm to do the work. In this case we are using some standard library modules like sys, web ... Read More

Advertisements