How to re-write this bash script in Python?

Chris Angelico rosuav at gmail.com
Fri Jul 31 04:26:38 EDT 2015


On Fri, Jul 31, 2015 at 6:15 PM, Cameron Simpson <cs at zip.com.au> wrote:
>> For example, bash lacks
>> decent timezone support, so I can well believe random832's guess that
>> your five-hour offset is a simulation of that; but Python can do much
>> better work with timezones, so you can get that actually correct.
>
>
> Actually, bash has no timezone support but the date command _does_, and
> probably neither better nor worse than Python. All one has to do is set the
> TZ environment variable, eg (untested):
>
>  _year_gmt=$( TZ=GMT date +%Y )

That's assuming that it's converting against the current system
timezone. I don't know how you'd use `date` to convert between two
arbitrary timezones. But anyway, still justification to rewrite from
original spec rather than reimplementing the five-hour hack.

ChrisA



More information about the Python-list mailing list