How to re-write this bash script in Python?

Cameron Simpson cs at
Fri Jul 31 10:15:03 CEST 2015

On 31Jul2015 17:47, Chris Angelico <rosuav at> wrote:
>On Fri, Jul 31, 2015 at 4:31 AM,  <sutanu.das at> wrote:
>> #!/bin/bash
>> _year=$(date -d "-5 hour" +%Y)
>> _month=$(date -d "-5 hour" +%m)
>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 )

>Also, file handling, searching, and text manipulation and so on can
>usually be done more efficiently and readably in Python directly than
>by piping things through grep and awk.

Again, depends a bit on the data. But in the general case probably true.

Cameron Simpson <cs at>

More information about the Python-list mailing list