Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #94813
| From | Grant Edwards <invalid@invalid.invalid> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: How to re-write this bash script in Python? |
| Date | 2015-07-31 14:26 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <mpg0ik$mfi$1@reader1.panix.com> (permalink) |
| References | <b07086dc-0946-4398-b621-23d564d54507@googlegroups.com> <mailman.1110.1438328836.3674.python-list@python.org> |
On 2015-07-31, Chris Angelico <rosuav@gmail.com> wrote:
> There are two basic approaches to this kind of job.
>
> 1) Go through every line of bash code and translate it into
> equivalent Python code. You should then have a Python script which
> blindly and naively accomplishes the same goal by the same method.
In my experience, that works OK for C (with a little post-translation
tweaking and re-factoring). But, it's a pretty lousy method for bash
scripts. There are a lot of things that are trivial in Python and
complex/hard in bash (and a few vice versa), so a direct translation
usually turns out to be a mess. You end up with a lot of Python code
where only a couple lines are really needed. You also end up doing
things in a bizarre manner in Python because the simple, easy, right
way wasn't supported by bash.
> 2) Start by describing what you want to accomplish, and then
> implement that in Python, using algorithmic notes from the bash code.
>
> The second option seems like a lot more work, but long-term it often
> isn't, because you end up with better code.
And the code works. :)
For bash, I really recommend 2)
--
Grant Edwards grant.b.edwards Yow! GOOD-NIGHT, everybody
at ... Now I have to go
gmail.com administer FIRST-AID to my
pet LEISURE SUIT!!
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to re-write this bash script in Python? sutanu.das@gmail.com - 2015-07-30 11:31 -0700
Re: How to re-write this bash script in Python? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-30 20:36 +0100
Re: How to re-write this bash script in Python? random832@fastmail.us - 2015-07-30 16:17 -0400
Re: How to re-write this bash script in Python? Chris Angelico <rosuav@gmail.com> - 2015-07-31 17:47 +1000
Re: How to re-write this bash script in Python? Grant Edwards <invalid@invalid.invalid> - 2015-07-31 14:26 +0000
Re: How to re-write this bash script in Python? Chris Angelico <rosuav@gmail.com> - 2015-08-01 00:53 +1000
csiph-web