[Tutor] Pass arguments from bash script to embedded python script
David L Neil
PyTutor at DancesWithMice.info
Mon Oct 21 14:42:02 EDT 2019
On 22/10/19 2:45 AM, Stephen P. Molnar wrote:
> First of all, let me emphasize that this is not a homework assignment.
>
> I have a large number of data files form a Quantum Chemistry program
> which all have the same format.
>
> I have written a short python script to extract the data required for
> another program.
...
> and I have a bash script in which I have embedded the python script:
...
> 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'
>
> where fname and fname1 are three typical data files.
>
> my problem is how do I pass the argument's in the two files from the
> bash script to the python script? It has been suggested to me that the
> solution is an implementation of the sys/.argv function but it seems
> that every reference that I can find goes the other way from python to
> bash.
>
> 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.
- over-simplified but useful to gain context,
How to use sys.argv in Python:
https://www.pythonforbeginners.com/system/python-sys-argv
- the recommended* Python library is argparse
https://docs.python.org/3/library/argparse.html
(much of the discussion/tutorial deals with offering 'help' responses to
incorrect cmdLN instruction, but that can be skipped in a personal
implementation)
* previous coding-tools have been deprecated, even as they appear more
frequently in web-tutorials, etc.
May I recommend that you do as much as possible in Python, even
(assuming I've understood the approach) reading the 'command files'
there, rather than trying to do more in BASH.
PS I replied to your (previous) personal msg, but SBC's email-blocker,
blocked!
--
Regards =dn
More information about the Tutor
mailing list