I would like to take all my simple math programs for basic financial ratios and compile it into one program where I could print the list of the programs and allow the user to select the one in which he or she is wishing to run. How would this be accomplished?
What I have tried so far has ended up in just running t开发者_如何转开发hrough all of the programs and then allowing to state the one you wish to do after you have gone through all the previous ones ex: opening the file and running it, going through each one the having to put margin() to run the program margin().
Thank you for your help in advance. I am new to programing and all my experience is self taught through readings and videos and I wish to do this in python the language I am most familiar with.
I think I understand what you are looking for, but please comment if I'm not understanding you correctly.
One of the easiest ways to accomplish what you are looking for is to just use the python prompt itself. If you put all your programs in one file (making sure that there are no overlapping names) then what you could call those functions from one program, call it masterprogram.py In your prompt then, import masterprogram to get started
Running a dir(masterprogram)
will list all the functions of your masterprogram, and running help(masterprogram.somefunction)
will print the documentation for that function.
If you would like an example of how this would work, try opening up your python prompt and running observe the following:
>>> import math
>>> dir(math)
['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan',
'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'er
fc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gam
ma', 'hypot', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'mod
f', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']
>>> help(math.ceil)
Help on built-in function ceil in module math:
ceil(...)
ceil(x)
Return the ceiling of x as a float.
This is the smallest integral value >= x.
>>>
精彩评论