How to re-write this bash script in Python?

Cameron Simpson cs at zip.com.au
Fri Jul 31 04:15:03 EDT 2015


On 31Jul2015 17:47, Chris Angelico <rosuav at gmail.com> wrote:
>On Fri, Jul 31, 2015 at 4:31 AM,  <sutanu.das at gmail.com> 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.

Cheers,
Cameron Simpson <cs at zip.com.au>



More information about the Python-list mailing list