Trim Tuples by N Elements in Python

AmitDiwan
Updated on 15-Apr-2021 13:15:35

212 Views

When it is required to trim a list of tuples by a specific number of elements, the ‘del’ operator can be used.Below is a demonstration of the same −Example Live Demomy_list = [(1, 2, 11), (99, 76, 34, 89), (3.08, 11.56), ("Hi", "Will"), ("Rob", 'Ron')] n = 2 print("The list is :") print(my_list) print("The value of N is") print(n) del my_list[n] print("The list after deleting N elements is :") print(my_list)OutputThe list is : [(1, 2, 11), (99, 76, 34, 89), (3.08, 11.56), ('Hi', 'Will'), ('Rob', 'Ron')] The value of N is 2 The list after deleting N elements is : [(1, ... Read More

Change Focus Between Text Widgets in Tkinter

Dev Prakash Sharma
Updated on 15-Apr-2021 13:13:45

1K+ Views

In various applications, tkinter widgets are required to be focused to make them active. Widgets can also grab focus and prevent the other events outside the bounds. To manage and give focus to a particular widget, we generally use the focus_set() method. It focuses the widget and makes them active until the termination of the program.ExampleIn the following example, we have created two text widgets and we will change the focus from one text widget to another text widget simultaneously using a button widget. Thus, changing the focus is easy by defining two methods which can be handled through the ... Read More

Find Number of Times Every Day Occurs in a Year in Python

AmitDiwan
Updated on 15-Apr-2021 13:13:41

616 Views

When it is required to find the number of times every day of the week occurs in a year, a list is defined, and it is iterated over, and is count is incremented respectively.Below is a demonstration of the same −Example Live Demoimport math def num_of_occurrence( n, firstday):    my_days = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ]    my_count= [4 for i in range(0, 7)]    my_position = -1    for i in range(0, 7):       if (first_day == my_days[i]):          my_position = i          break ... Read More

Convert Date String to Timestamp in Python

AmitDiwan
Updated on 15-Apr-2021 13:12:49

1K+ Views

When it is required to convert a string into a timestamp, the ‘mktime’ method is used. This method is present in the ‘time’ package.Below is a demonstration of the same −Example Live Demoimport time import datetime my_string = "24/03/2021" print("The date string is :") print(my_string) print("The timestamp is :") print(time.mktime(datetime.datetime.strptime(my_string, "%d/%m/%Y").timetuple()))OutputThe date string is : 24/03/2021 The timestamp is : 1616544000.0ExplanationThe required packages are imported.The string is defined, and displayed on the console.The ‘mktime’ method from time package is called, and the string is passed as parameter to it.The ‘strptime’ is used to remove the extra spaces or symbols from ... Read More

Use Boto3 to Paginate Through Crawlers in AWS Glue

Ashish Anand
Updated on 15-Apr-2021 13:12:45

413 Views

In this article, we will see how to paginate through all crawlers present in AWS Glue.ExamplePaginate through all crawlers from AWS Glue Data Catalog that is created in your account.Problem Statement: Use boto3 library in Python to paginate through all crawlers from AWS Glue Data Catalog that is created in your accountApproach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: max_items, page_size and starting_token are the parameters for this function.max_items denote the total number of records to return. If the number of available records > max_items, then a NextToken will be provided in the ... Read More

Change Command Method for Tkinter Button in Python

Dev Prakash Sharma
Updated on 15-Apr-2021 13:11:16

5K+ Views

The significance of Button widget is that it is used for handling events to perform certain operations in the application. In order to handle such events, we generally define a method which contains certain operations.Let us suppose we want to change the event method after initializing the button. We can configure the Button and its handler using configure(options) method. Thus, by defining a new method and configuring the button we can trigger a new event with the same button.Example#Import tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("750x250") #Define ... Read More

Adding a Scrollbar to a Group of Widgets in Tkinter

Dev Prakash Sharma
Updated on 15-Apr-2021 13:08:31

723 Views

Let’s suppose you want to add a scrollbar to a group of widgets in an application, then you can use the Scrollbars property in tkinter. Adding Scrollbars to a group of widgets can be achieved by Scrollbar(....options).ExampleIn this example, we will define a group of Listbox widgets and then add a vertical scrollbar to make the list scrollable.#Import the required library from tkinter import * #Create an instance of tkinter frame or window win = Tk() #Define the geometry win.geometry("750x400") #Create a listbox listbox= Listbox(win) listbox.pack(side =LEFT, fill = BOTH) #Create a Scrollbar scrollbar = Scrollbar(win) ... Read More

Update Workflow Details in AWS Glue Catalog Using Boto3

Ashish Anand
Updated on 15-Apr-2021 13:08:22

295 Views

In this article, we will see how to update the details of a workflow in AWS Glue Catalog.ExampleProblem Statement: Use boto3 library in Python to update details of a workflow that is created in your account.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: workflow_name is the required parameter for this function. Description and deault_run_properties are optional parameter. It updates the details of a given workflow.Step 3: Create an AWS session using boto3 lib. Make sure region_name is mentioned in the default profile. If it is not mentioned, then explicitly pass the region_name while ... Read More

Update Crawler Scheduler in AWS Glue Data Catalog Using Boto3

Ashish Anand
Updated on 15-Apr-2021 13:08:00

411 Views

In this article, we will see how to update the scheduler of a crawler present in an AWS account.ExampleProblem Statement: Use boto3 library in Python to update the scheduler of a crawler.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: crawler_name and scheduler are the required parameters in this function.The format of scheduler should be as cron(cron_expression). Cron_Expression can be written as (15 12 * * ? *), i.e., the crawler will run every day at 12:15UTC.Step 3: Create an AWS session using boto3 lib. Make sure region_name is mentioned in the default profile. ... Read More

Create a Lap Timer in Python

AmitDiwan
Updated on 15-Apr-2021 13:07:41

599 Views

When it is required to create a lap timer using Python, the ‘time’ method is used. The number of laps is predefined, and a try catch block is defined, to start the lap timer.Below is a demonstration of the same −Example Live Demoimport time start_time=time.time() end_time=start_time lap_num=1 print("Click on ENTER to count laps.Press CTRL+C to stop") try:    while True:       input()       time_laps=round((time.time() - end_time), 2)       tot_time=round((time.time() - start_time), 2)       print("Lap No. "+str(lap_num))       print("Total Time: "+str(tot_time))       print("Lap Time: ... Read More

Advertisements