-1

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.

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
Yozy Opto
  • 23
  • 5
  • 1
    what 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 Answers1

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