'I am always receiving an AttributeError
Here is my code:
import time
import datetime
import pytz
print('--'*62)
cont = 0
print('MENU'.center(115))
print('--'*62)
my_timezones = {}
l = list() # MAIN LIST
l.append('0')
my_timezones['United Arab Emirates'] = pytz.country_timezones['AE']
my_timezones['Canada'] = pytz.country_timezones['CA'][20]
my_timezones['South Korea'] = pytz.country_timezones['KR']
my_timezones['United States'] = pytz.country_timezones['US'][17]
my_timezones['New Zeland'] = pytz.country_timezones['NZ'][0]
my_timezones['Norway'] = pytz.country_timezones['NO']
my_timezones['Ireland'] = pytz.country_timezones['IE']
my_timezones['Netherlands'] = pytz.country_timezones['NL']
my_timezones['Switzerland'] = pytz.country_timezones['CH']
l.append(my_timezones['United Arab Emirates'])
l.append(my_timezones['Canada'])
l.append(my_timezones['South Korea'])
l.append(my_timezones['United States'])
l.append(my_timezones['New Zeland'])
l.append(my_timezones['Norway'])
l.append(my_timezones['Ireland'])
l.append(my_timezones['Netherlands'])
l.append(my_timezones['Switzerland'])
print(l)
print('Cod Country Timezone')
for c in my_timezones.keys():
cont+=1
print(f'{cont}', end=' ')
print(f'{c}', end='')
print(f'{my_timezones[c]}'.center(45))
print('--'*62)
while True:
which = int(input('Which one? '))
if which == 0:
break
else:
print(f'Local Time: {datetime.datetime.now()}')
print(f'UTC time: {datetime.datetime.utcnow()}')
try:
baby = l[which]
timezone = pytz.timezone(baby) # THE LINE WHERE IS NOT WORKING
time = datetime.datetime.now(tz=timezone)
print(f'{l[which]} time: {time}')
except IndexError:
print('SORRY! WE DIDN´T FIND IT!')
for c in l:
print(c)`` ``
Then I receive this error:
AttributeError: 'list' object has no attribute 'upper'
I really don´t know how to fix it, because I don´t know even what is the source of the problem, so please I need your help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
