Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #94805

Re: How to re-write this bash script in Python?

Return-Path <cameron@cskk.homeip.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.05; 'bash': 0.07; 'correct.': 0.07; 'variable,': 0.07; 'subject:How': 0.09; 'grep': 0.09; 'handling,': 0.09; 'subject:script': 0.09; 'worse': 0.09; 'python': 0.10; 'python.': 0.11; '>on': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'simpson': 0.16; 'wrote:': 0.16; '2015': 0.20; 'to:name :python-list@python.org': 0.20; '31,': 0.22; 'cheers,': 0.22; 'am,': 0.23; 'bit': 0.23; 'header:In-Reply-To:1': 0.24; 'header :User-Agent:1': 0.26; 'command': 0.26; 'chris': 0.26; 'fri,': 0.27; 'environment': 0.29; 'guess': 0.31; 'probably': 0.31; 'skip:_ 10': 0.32; 'true.': 0.33; 'file': 0.34; 'text': 0.35; 'done': 0.35; 'but': 0.36; 'data.': 0.36; 'depends': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'support,': 0.37; 'charset:us-ascii': 0.37; 'things': 0.38; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'more': 0.63; 'believe': 0.66; 'cameron': 0.66; 'jul': 0.72; 'received:61': 0.72; 'actually,': 0.84; 'lacks': 0.84; 'piping': 0.84; 'subject:write': 0.84; 'subject:this': 0.85; 'simulation': 0.91
X-Authentication-Info Submitted using ID cskk@bigpond.com
X-Authority-Analysis v=2.0 cv=Os7NOlDt c=1 sm=1 a=BTUCPfNp+rZco6aAFjjDqw==:17 a=vrnE16BAAAAA:8 a=ZtCCktOnAAAA:8 a=yEdEr6MRgwAA:10 a=zOBTXjUuO1YA:10 a=pGLkceISAAAA:8 a=zamRGsdcW2F1GGyS8yIA:9 a=CjuIK1q_8ugA:10 a=BTUCPfNp+rZco6aAFjjDqw==:117
Date Fri, 31 Jul 2015 18:15:03 +1000
From Cameron Simpson <cs@zip.com.au>
To "python-list@python.org" <python-list@python.org>
Subject Re: How to re-write this bash script in Python?
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii; format=flowed
Content-Disposition inline
In-Reply-To <CAPTjJmoKYt3=fmz0q=azgVCXTs0YCfeiJZ3fYCSVe7cEzAHkPw@mail.gmail.com>
User-Agent Mutt/1.5.23 (2014-03-12)
References <CAPTjJmoKYt3=fmz0q=azgVCXTs0YCfeiJZ3fYCSVe7cEzAHkPw@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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.1111.1438330518.3674.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1438330518 news.xs4all.nl 2840 [2001:888:2000:d::a6]:33284
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 4133
X-Received-Body-CRC 1888883220
Path csiph.com!usenet.pasdenom.info!news.stben.net!border1.nntp.ams1.giganews.com!border2.nntp.ams1.giganews.com!nntp.giganews.com!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Xref csiph.com comp.lang.python:94805

Show key headers only | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: How to re-write this bash script in Python? Cameron Simpson <cs@zip.com.au> - 2015-07-31 18:15 +1000

csiph-web