问题
I've been working on a Python library that uses a C extension module to do ISO 8601 parsing.
Part of that work requires the creation of tzinfo objects, which is by far the slowest part of the parse. Calls out to Python implementations of tzinfo (currently pytz.FixedOffset
) are simply too slow.
In Python 3.7, datetime.timezone
is finally exposed to the C-API. My code takes adavantage of it, and gets a tremendous performance boost from using a C implementation instead of a Python one. I'd love to find a similar C implementation that I could use for Python < 3.6. Perhaps a "backport" of 3.7's datetime.timezone
?
I've seen many Python implementations of tzinfo (pytz
, datetuil.tz
, django.utils.timezone
, psycopg2.tz
) but none in C.
Are there C implementations of tzinfo
(besides datetime.timezone
)?
回答1:
After searching some more, I ended up finding an implementation in Pendulum's low level ISO 8601 parser.
Edit: This implementation was eventually used in my backport of datetime.fromisoformat
来源:https://stackoverflow.com/questions/50336229/are-there-any-datetime-tzinfo-implementations-in-c