[Tutor] functions, system statements, sleep
Fri, 19 Jan 2001 17:08:24 -0000
> I'm a complete idiot,
No you're a beginner that's all. Different concepts :-)
> but when I create a function in Python,
> how do I run it? Say I create a function that has a main
> menu. And after the user goes through the introductory, how
> can I run the main_menu function?
Are you still using the python >>> prompt?
If so you just type the name of the function with parentheses,
possibly comntaining some argument values.
If on the other hand your function is in a file called menu.py
and you are writing a program that uses it you will have to
>>> import menu
first then call it by prepending the module name
If you are writing you main program in a file called myprog.py
then within that you would define main_menu then call it:
# do whatever you do
# do some other stuff
main_menu() # call main_menu
OR if main_menu is in menu.py:
> How can I get the python interpreter to run a Unix system
> function? Like say I want it to use 'clear'
Noe that this won't return any values so something like
cat, ls etc will just display to stdout, not give you any
results back. For that you need popen()...
> And is there a sleep function in Python, that will make it
> wait for a couple of seconds before doing anything?
> one in Perl, and I find it really useful.
Most Perl functions are available in Python but they will
be found in a module rather than builtin a Perl does it.
If in doubt look in the Python documentation in the Standard
Library Reference index.