Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

# Try catch block to catch Errors

try:
f = open('Weather_75252.json', 'r') # Reading the file in read mode

data = eval(f.read()) # Reading the data and using eval to convert to


dictionary

# Printing the data


print('Zip: 75252')
print('weather description:', data['weather'][0]['description'])
print('Temperature:', data['main']['temp'])
print('Pressure:', data['main']['pressure'])
print('Humidity:', data['main']['humidity'])
print('Sunrise:', data['sys']['sunrise'])

# Closing the file as good practice


f.close()

# Catching Exceptions
except Exception as e:
print(e)

You might also like