Python Forum
Make bash call my own Python modules
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Make bash call my own Python modules
#7
Thanks for the replies. I know this must actually be quite simple to do. I just do not know how. I think I am not explaining myself clearly.

An example:

I have another loooong Python program. "all_steps_in_1_Email.py", nearly 1000 lines. It gets emails from students, downloads them, saves them, marks their answers, writes the results to my timetable, calculates % scores, attendance, writes everything to Excel, formats the Excel file. It has 7 functions. I need all of them in sequence. There is no need to choose any particular function. So I just run all_steps_in_1_Email.py in bash. Works well for hundreds of students. Does my marking and inserts the results to my timetable in about 10 seconds!

Now I want this little program, makeWebpage.py, to make my homework webpage each week.

@DeaD_EyE

I modify the sys.path so Python can find my modules easily. That works great in a Python shell like Idle. In fact, all my code works well in the Python shell. It does just what I want it to do.

Now I want to run makeWebpage.py in a bash terminal. The only difference to all_steps_in_1_Email.py is, I will not need all the functions every time. I need to choose which one to use.

I make all my little functions available, but I may not need all of them.

How can I call the 1 or 2 I want? How to assign just 1 or 2 to myString in bash?

Someone advised to use argparse, but I can't understand exactly how to implement it.

At the moment, I do it like this:

1. Use 1 of my functions in bash, say makeTextboxes.py Save the output string as a text file called paragraph.
2. Run a simpler version of makeWebpage.py This takes my basic webpage, reads it in with readlines(), then changes the title of the webpage, the week number, the css file, the maximum score, the switch-off time, inserts "paragraph" at line 32, a few other things and saves the file as, for example, week10.html

All I want is to integrate 1 and 2, but 1 needs a choice of function in the bash shell.

I tried putting the functions in a list and also in a dictionary:

pyFiles = [makeHTMLCBs(), makeDropdownboxes(), makeHTMLtable(), makeHTML_RBs(), readLinesmakeTBs(), makeThankyouPHP()]
pyFiles = {'0': makeHTMLCBs(), '1': makeDropdownboxes(), '2': makeHTMLtable(), '3': makeHTML_RBs(), '4': readLinesmakeTBs(), '5': makeThankyouPHP()}
Either way, at runtime, Python immediately wants to execute the first function in the list or dictionary. I don't get a chance to choose say, myString = pyFiles[3]
Reply


Messages In This Thread
RE: Make bash call my own Python modules - by Pedroski55 - Apr-19-2019, 09:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems passing arguments containing spaces to bash script and then on to python kaustin 6 652 Apr-03-2024, 08:26 PM
Last Post: deanhystad
  How to see the date of installation of python modules. newbieAuggie2019 4 1,797 Mar-31-2023, 12:40 PM
Last Post: newbieAuggie2019
  Python modules for accessing the configuration of relevant paths Imago 1 1,479 May-07-2022, 07:28 PM
Last Post: Larz60+
  Call a bash script from within a Python programme Pedroski55 6 2,577 Dec-06-2021, 01:53 PM
Last Post: DeaD_EyE
  Showing and saving the output of a python file run through bash Rim 3 2,615 Oct-06-2021, 10:48 AM
Last Post: gerpark
  Python modules to extract data from a graph? bigmit37 5 22,786 Apr-09-2021, 02:15 PM
Last Post: TysonL
  Where to add own python modules in WinPython? HinterhaeltigesSchlaengelchen 1 2,357 Jan-21-2021, 07:45 PM
Last Post: snippsat
  Including modules in Python using sys.path.append JoeDainton123 1 3,034 Aug-24-2020, 04:51 AM
Last Post: millpond
  How to kill a bash script running as root from a python script? jc_lafleur 4 6,119 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  how to get PID's of linux commands executed through python modules? Manikandan_PS 4 3,156 Mar-12-2020, 07:16 AM
Last Post: Manikandan_PS

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020