如何列出所有假日';在python中使用假日模块的每个国家/地区的日期?
我试图用python为许多国家/地区查找带有假日包的假日日期,但不是这样逐个编写:如何列出所有假日';在python中使用假日模块的每个国家/地区的日期?,python,python-3.x,python-holidays,Python,Python 3.x,Python Holidays,我试图用python为许多国家/地区查找带有假日包的假日日期,但不是这样逐个编写: import holidays for date in holidays.UnitedKingdom(years=2011).items(): print(str(date[0])) for date in holidays.Argentina(years=2011).items(): print(str(date[0])) for i in dir(holidays): for j
import holidays
for date in holidays.UnitedKingdom(years=2011).items():
print(str(date[0]))
for date in holidays.Argentina(years=2011).items():
print(str(date[0]))
for i in dir(holidays):
for j in range(2010,2016):
holidays.i(years=2011).keys()
我正试图用这样一个函数来实现这一点:
import holidays
for date in holidays.UnitedKingdom(years=2011).items():
print(str(date[0]))
for date in holidays.Argentina(years=2011).items():
print(str(date[0]))
for i in dir(holidays):
for j in range(2010,2016):
holidays.i(years=2011).keys()
我知道每个国家的名字都是一个字符串,但我想把它实现为一个循环,如果你有任何建议,请与我分享。
谢谢。首先:
pip show holidays
然后将位置复制到locationVariable
import holidays
import os
locationVariable = ""
countries = [name.split(".py")[0].replace("_"," ") for name in os.listdir(locationVariable+"holidays/countries/") if name.endswith(".py") and not name.startswith("__")]
print("List of countries are : " + str(len(countries)))
for i in countries:
for j in range(2010,2021):
try:
print(getattr(holidays,i.title().replace(" ",""))(years=j).keys())
except:
print("unable to iterate "+i.title().replace(" ",""))
break
名称的格式似乎不一致(对于Hongkong
),请使用
如果有用,请确保回答mark。请在问题中添加一个您预期输出的示例。谢谢回答,这对我很有帮助。