I've been searching around for the contents of pytz.all_timezones, but have found nothing. Just people saying "Use pytz.all_timezones" but that would mean I'd have to copy every single timezone from the output. I need a LIST of all timezones in pytz.all_timezones, not just a message telling me to use it.
Asked
Active
Viewed 368 times
-1
-
1what specifically is your question? btw. `pytz` is deprecated, try to avoid using it. Instead, use zoneinfo; see [here for instance](https://stackoverflow.com/a/64861179/10197418) how to obtain available tz names. – FObersteiner Dec 23 '22 at 16:35
1 Answers
1
As the previous answer mentioned, pytz.all_timezones
is already a list of strings. In your code, you could access this list and extract the values you need from it: there is probably no need to create a different list for that.
You could save the content of the timezones list to a text file like this:
# open file in write mode
with open(r'pytz_all_timezones.txt', 'w') as fp:
for item in pytz.all_timezones:
# write each item on a new line
fp.write(f"{item}\n")

Carlos Melus
- 1,472
- 2
- 7
- 12
-
-
-
I needed a list of timezones for my Discord bot to give to people (it'd clog things up if it were sent in messages) – Yozy Opto Dec 23 '22 at 16:48
-
1Just give them this link: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones – Matt Johnson-Pint Dec 23 '22 at 17:19