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.
CodePudding user response:
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")
CodePudding user response:
LIST of all timezones in pytz.all_timezones https://gist.github.com/heyalexej/8bf688fd67d7199be4a1682b3eec7568
CodePudding user response:
The all_timezones
attribute is a list of strings, where each string is the name of a timezone
import pytz
timezones = pytz.all_timezones
print(timezones)
You can also use the common_timezones
attribute to get a list of the most commonly used timezones
import pytz
common_timezones = pytz.common_timezones
print(common_timezones)
You can also write it in file
import pytz
timezones = pytz.all_timezones
with open('timezones.txt', 'w') as file:
for timezone in timezones:
file.write(timezone '\n')
Or even the copy
function from the pyperclip
library to copy the list to your clipboard
import pytz
import pyperclip
timezones = pytz.all_timezones
timezones_string = '\n'.join(timezones)
pyperclip.copy(timezones_string)