[Tutor] functions, system statements, sleep

Jose Amoreira amoreira@mercury.ubi.pt
Fri, 19 Jan 2001 14:58:04 +0000


Hello!

Matthias Hager wrote:

> I'm a complete idiot, 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?
>

I'm much of a genius myself. Anyway, if you defined a function you can run it just by typing its name:
pandora:scripts$ python
Python 2.0 (#4, Nov 24 2000, 11:42:48)
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> def f(x):
...     return x**2
...
>>> f(2)
4
>>>
Maybe your problem is that you don't supply the parenthesis? Even if the function requires no arguments, you still have to put the parenthesis to run it, as in
>>> my_function()
I don't know if this answers your question, maybe you could give more details?

>
> How can I get the python interpreter to run a Unix system function? Like say I want it to use 'clear' (Adequately used to clear the screen) How can I get my program, runing in command line to do that?
>

You can use the os module,  and the command os.system('command'), or the os.popen() commands

>
> And is there a sleep function in Python, that will make it wait for a couple of seconds before doing anything? There is one in Perl, and I find it really useful.
>
> --

Yes, but I've never used. It ist time.sleep()
Hope it helps!