Apr-19-2019, 09:39 PM
(This post was last modified: Apr-19-2019, 09:39 PM by Pedroski55.)
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:
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]