Python Articles - Page 617 of 1048

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

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

2K+ 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

How to use Boto3 to add tags in AWS Glue Resources

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

1K+ Views

In this article, we will see how a user can add tags in AWS Glue Resources.ExampleAdd tags “glue-db: tests” in AWS glue database. Problem Statement: Use boto3 library in Python to add 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_dict 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_dict should be as {“key”:”value”, ..}Step 3: Create an AWS session using boto3 lib. Make sure region_name is mentioned in the default profile. If it is ... Read More

Python Program to Create a Lap Timer

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

638 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

Python program to find difference between current time and given time

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

429 Views

When it is required to find the difference between the current time and a given time, a method can be defined, that takes the hours, minutes, and seconds as parameter. It then calculates the difference between two given times.Below is a demonstration of the same −Example Live Demodef difference_time(h_1, m_1, h_2, m_2):    t_1 = h_1 * 60 + m_1    t_2 = h_2 * 60 + m_2    if (t_1 == t_2):       print("The times are the same")       return    else:       diff = t_2-t_1    hours = (int(diff / ... Read More

Find yesterday’s, today’s and tomorrow’s date in Python

AmitDiwan
Updated on 15-Apr-2021 13:05:43

510 Views

When it is required to find yesterday, today and tomorrow’s date with respect to current date, the current time is determined, and a method is used (in built) that helps find previous day and next day’s dates.Below is a demonstration of the same −Example Live Demofrom datetime import datetime, timedelta present = datetime.now() yesterday = present - timedelta(1) tomorrow = present + timedelta(1) print("Yesterday was :") print(yesterday.strftime('%d-%m-%Y')) print("Today is :") print(present.strftime('%d-%m-%Y')) print("Tomorrow would be :") print(tomorrow.strftime('%d-%m-%Y'))OutputYesterday was : 05-04-2021 Today is : 06-04-2021 Tomorrow would be : 07-04-2021ExplanationThe required packages are imported into the environment.The current date is determined ... Read More

Python Program to print the pattern ‘G’

AmitDiwan
Updated on 15-Apr-2021 13:05:23

619 Views

When it is required to print the pattern of the letter ‘G’ using ‘*’, a method can be defined, and nested loop can be used to iterate through the numbers and print ‘*” to form a ‘G’ pattern.Below is a demonstration of the same −Exampledef display_pattern(my_line):    my_pattern=""    for i in range(0, my_line):       for j in range(0, my_line):          if ((j == 1 and I != 0 and I != my_line-1) or ((I == 0 or I == my_line-1) and j > 1 and j < my_line-2) or (I == ((my_line-1)/2) and j ... Read More

Python Program to Display Fibonacci Sequence Using Recursion

AmitDiwan
Updated on 15-Apr-2021 13:04:56

421 Views

When it is required to print the fibonacci sequence using the method of recursion, a method can be declared that calls the same method again and again until a base value is reached.Below is a demonstration of the same −Example Live Demodef fibonacci_recursion(my_val):    if my_val

How to use Boto3 to stop a crawler in AWS Glue Data Catalog

Ashish Anand
Updated on 15-Apr-2021 13:02:17

294 Views

In this article, we will see how a user can stop a crawler present in an AWS Glue Data Catalog.ExampleProblem Statement: Use boto3 library in Python to stop a crawler.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: crawler_name is the parameter in this function.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 creating the session.Step 4: Create an AWS client for glue.Step 5: Now use the stop_crawler function and pass the parameter crawler_name ... Read More

How to use Boto3 to stop a workflow in AWS Glue Data Catalog

Ashish Anand
Updated on 15-Apr-2021 13:01:57

559 Views

In this article, we will see how a user can stop a workflow present in an AWS account.ExampleProblem Statement: Use boto3 library in Python to stop a workflow.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: workflow_name and run_id are the required parameters in this function.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 creating the session.Step 4: Create an AWS client for glue.Step 5: Now use the stop_workflow_run function and pass the parameter ... Read More

How to use Boto3 to start a workflow in AWS Glue Data Catalog

Ashish Anand
Updated on 15-Apr-2021 13:01:39

773 Views

In this article, we will see how a user can start a workflow in AWS Glue Data Catlog.ExampleProblem Statement: Use boto3 library in Python to start a workflow.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: workflow_name is parameter in this function.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 creating the session.Step 4: Create an AWS client for glue.Step 5: Now use start_workflow_run function and pass the parameter workflow_name as Name.Step 6: It returns ... Read More

Advertisements