[Tutor] Pass arguments from bash script to embedded python script

David bouncingcats at gmail.com
Mon Oct 21 18:49:03 EDT 2019


On Tue, 22 Oct 2019 at 00:45, Stephen P. Molnar <s.molnar at sbcglobal.net> wrote:

[...]

> and I have a bash script in which I have embedded the python script:

Why is the task split between two scripts in two different languages?
This seems misguided and to introduce unnecessary complications,
given the simple nature of both scripts that were shown.

[...]

> > while IFS= read -r d
> > do
> >     python3 DeltaGTable_V_sw.py
> > done <ligand.list

The functionality in that bash code is simple to achieve using Python.

[...]

> The ligand.list for the bash file have the format:
> >
> >> fname = ['C-VX3.log', '15-7.log', '14-7.log']
> >> fname1 = ['C-VX3', '15-7', '14-7'

I wonder what generates that content? Because it strongly
resembles runnable Python code. See below.

I may be misunderstanding, but using Bash to read files
containing what looks like Python source code looks like a
confused design. Is there some reason for that?

It looks like Bash is used to parse data out of Python syntax
before then passing that data to a Python script. Yes, it could
be made to work, but it looks like a confused and inefficient design.

A cleaner approach would be to write one Python script that does
everything required, and avoid all the unnecessary parsing and
argument passing. If the Bash script was complicated, I wouldn't
advocate this because it would be a lot of work. But the Bash
script you showed us is trivial.

> So my question is what question should I be goggling? I am not looking
> for someone to write the script for me, but pointers in the correct
> direction.

Possible approaches:

1) In Python, how to read a file line-by-line, and parse data out of it.
If that is actually needed? ...

2) Or, if it is not a security risk and you control the file content, you might
be able to directly apply Python's exec() function [1] directly to the
entire content of your ligand.list file. In that case there would be no
need to read the ligand.list file line-by-line.

[1] https://docs.python.org/3/library/functions.html#exec


More information about the Tutor mailing list