[Tutor] functions, system statements, sleep
Fri, 19 Jan 2001 10:59:59 -0500
On Fri, Jan 19, 2001 at 06:07:31AM -0800, 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?
First you will have to un-learn all the bad habits Perl taught you.
As the other poster mentioned, you need to use the parenthesis for all
function calls. Also, there is no magic $_ variable that will be
given to functions if you forget to specify the argument (you must
explicitly pass all necessary arguments to functions). The python
community takes the viewpoint that "explicit is better than implicit",
in my opinion because it becomes easier to read, understand and debug
when the interpreter (or compiler) doesn't do any automagic for you.
| 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?
There is the os.system() function, but I would advise against making
heavy use of it. Using it is likely to render your programs
unportable to different platforms. An alternative to calling the
program "clear" would be to print several blank lines. Suppose I
assume the terminal has 24 lines (a vt100 emulator) :
for i in range( 24 ) :
This could be extended by somehow (maybe, it might not be possible)
querying the terminal for the number of lines it has, or just pick a
number that is bigger than any terminal. (Say 500, for an extremist
There is also the ncurses module, but only exists for Unix systems.
This would give you much more flexible and powerful control of the
terminal's screen, but it still wouldn't work on other systems (ie
Windows, Mac, VMS (?), Amiga, etc).