Found 10476 Articles for Python

How to use Boto3 to to paginate through all databases present in AWS Glue

Ashish Anand
Updated on 15-Apr-2021 13:18:16

557 Views

In this article, we will see how to paginate through all databases present in AWS Glue.ExampleProblem Statement: Use boto3 library in Python to paginate through all databases 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 is parameter 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 response to resume pagination.page_size denotes the size of each page.starting_token helps to paginate, and it ... Read More

Trim tuples by N elements in Python

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

215 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

How to use Boto3 to paginate through all crawlers present in AWS Glue

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

417 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

Find number of times every day occurs in a Year in Python

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

619 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

How to use Boto3 to update the details of a workflow in AWS Glue Catalog

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

298 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

How to use Boto3 to update the scheduler of a crawler in AWS Glue Data Catalog

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

415 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

How to use Boto3 to remove tags from AWS Glue Resources

Ashish Anand
Updated on 15-Apr-2021 13:07:18

311 Views

In this article, we will see how to remove tags from AWS Glue Resources.ExampleRemove tags “glue-db: tests” in AWS glue database. Problem Statement: Use boto3 library in Python to remove tags in AWS Glue Resources.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: resource_arn and tags_list are the required parameters in this function.The format of resource_arn should be as following −Catalogarn:aws:glue:region:account-id:catalogDatabasearn:aws:glue:region:account-id:database/database nameTablearn:aws:glue:region:account-id:table/database name/table nameConnectionarn:aws:glue:region:account-id:connection/connection nameCrawlerarn:aws:glue:region:account-id:crawler/crawler-nameJobarn:aws:glue:region:account-id:job/job-nameTriggerarn:aws:glue:region:account-id:trigger/trigger-nameDevelopment endpointarn:aws:glue:region:account-id:devEndpoint/development-endpoint-nameMachine learning transformarn:aws:glue:region:account-id:mlTransform/transform-idtags_list should be as [“key1, key2…]Step 3: Create an AWS session using boto3 lib. Make sure region_name is mentioned in the default profile. If it is not mentioned, ... Read More

How to use Boto3 to get tags from an AWS Glue Resources

Ashish Anand
Updated on 15-Apr-2021 13:06:58

1K+ Views

In this article, we will see how the users can get the tags associated in AWS Glue Resources.ExampleGet tags “glue-db: tests” from AWS glue database. Problem Statement: Use boto3 library in Python to get the tags from AWS Glue Resources.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: resource_arn is the required parameter in this function.Format of resource_arn should be as following −Catalogarn:aws:glue:region:account-id:catalogDatabasearn:aws:glue:region:account-id:database/database nameTablearn:aws:glue:region:account-id:table/database name/table nameConnectionarn:aws:glue:region:account-id:connection/connection nameCrawlerarn:aws:glue:region:account-id:crawler/crawler-nameJobarn:aws:glue:region:account-id:job/job-nameTriggerarn:aws:glue:region:account-id:trigger/trigger-nameDevelopment endpointarn:aws:glue:region:account-id:devEndpoint/development-endpoint-nameMachine learning transformarn:aws:glue:region:account-id:mlTransform/transform-idStep 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 ... Read More

Advertisements