Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76629
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'output': 0.05; 'string': 0.09; 'act,': 0.09; 'assuming': 0.09; 'latter': 0.09; 'parsing': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:How': 0.10; 'api': 0.11; 'bug': 0.12; 'assumptions': 0.16; 'attributes,': 0.16; 'attributes:': 0.16; 'finney': 0.16; 'programmer,': 0.16; 'quirks': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; '>>>': 0.22; 'code,': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'string,': 0.24; 'least': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'skip:p 30': 0.29; 'writes:': 0.31; 'yes.': 0.31; 'worked': 0.33; 'subject:time': 0.33; 'skip:d 20': 0.34; 'but': 0.35; 'there': 0.35; 'library.': 0.36; 'ben': 0.38; 'depends': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'structure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'simply': 0.61; "you're": 0.61; "you'll": 0.62; 'skip:n 10': 0.64; 'details': 0.65; 'between': 0.67; 'benefit': 0.68; 'promise': 0.68; 'subject': 0.69; 'skip:r 30': 0.69; 'therefore': 0.72; 'contains.': 0.84; 'received:125': 0.84; 'subject:location': 0.84; '\xe2\x80\x9cthe': 0.91; 'directly.': 0.95 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Ben Finney <ben+python@benfinney.id.au> |
| Subject | Re: How to look up historical time zones by date and location |
| Date | Wed, 20 Aug 2014 11:53:45 +1000 |
| References | <53F2A8E2.9000804@gmail.com> <20140819231436.GA77365@cskk.homeip.net> <53F3FA7C.3060907@gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| X-Gmane-NNTP-Posting-Host | jigong.madmonks.org |
| X-Public-Key-ID | 0xAC128405 |
| X-Public-Key-Fingerprint | 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 |
| X-Public-Key-URL | http://www.benfinney.id.au/contact/bfinney-pubkey.asc |
| X-Post-From | Ben Finney <bignose+hates-spam@benfinney.id.au> |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
| Cancel-Lock | sha1:/m+riV+8p5NRKuLql+6A0dilJGY= |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.13185.1408499644.18130.python-list@python.org> (permalink) |
| Lines | 46 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1408499644 news.xs4all.nl 2865 [2001:888:2000:d::a6]:43729 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:76629 |
Show key headers only | View raw
luofeiyu <elearn2014@gmail.com> writes:
> >>> tz1
> <DstTzInfo 'Asia/Shanghai' LMT+8:06:00 STD>
> >>> repr(tz1)
> "<DstTzInfo 'Asia/Shanghai' LMT+8:06:00 STD>"
Yes. Remember that ‘repr’ is for the benefit of the programmer, and
there is no promise of what it contains.
> >>> x=repr(tz1)
> >>> x
> "<DstTzInfo 'Asia/Shanghai' LMT+8:06:00 STD>"
> >>> import re
> >>> re.search("LMT.+\s",x).group()
> 'LMT+8:06:00 '
This is wildly fragile. The ‘repr’ output depends on unpublished
attributes: implementation details not part of the API which therefore
can change without notice. You're then parsing a free-form string
assuming that it will contain a structure for the data you want.
All of those assumptions are subject to change without notification, and
the result would be a bug in your code, not the library.
At the least: Reduce the number of fragile links in that chain. If you
want access to unpublished attributes, then simply access them directly.
>>> import pytz
>>> tz1 = pytz.timezone("Asia/Shanghai")
>>> (zone_name, tzname, utcoffset, is_dst) = (tz1.zone, tz1._tzname, tz1._utcoffset, tz1._dst)
>>> zone_name, tzname, utcoffset, is_dst
('Asia/Shanghai', 'CST', datetime.timedelta(0, 28800), datetime.timedelta(0))
Then use those values however you like.
The values will still be subject to change without notice. But at least
you'll avoid parsing structured data from a string, and you'll avoid
whatever quirks go into the ‘repr’ output.
--
\ “The difference between a moral man and a man of honor is that |
`\ the latter regrets a discreditable act, even when it has worked |
_o__) and he has not been caught.” —Henry L. Mencken |
Ben Finney
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: How to look up historical time zones by date and location Ben Finney <ben+python@benfinney.id.au> - 2014-08-20 11:53 +1000
csiph-web