Monday, 7 July 2025

Python - 1

 

How to get all keys and value from dict


Dict1 = {'key1': 1, 'key2': 2, 'key3': 3}


for k, v in dict1.items():

    print(k, v)


File operations with Python


Read file


f = open("demofile.txt", "r")


print(f.read())




Loop through the file line by line:

f = open("demofile.txt", "r")

for x in f:

  print(x)


Write

‘A’ = append

‘W’ =write

f = open("demofile2.txt", "a")

f.write("Now the file has more content!")

f.close()


#open and read the file after the appending:

f = open("demofile2.txt", "r")

print(f.read())


Call Rest API and render page


import requests 

url = 'http://ES_search_demo.com/document/record/_search?pretty=true' 

data ='{ "query": { "bool": “True” }'


response = requests.post(url, data=data)

Lambda with profile


Lambda with STS


No comments:

Post a Comment