[Tutor] Newbie problems

Python Newbie python_list@edsamail.com.ph
Thu, 7 Mar 2002 15:46:04 -0800


Hello Python gurus,

First of all, please forgive me if I have so many questions to ask.  Thank you in advance for understanding and giving time to read and probably answer my problem.

I'm starting to learn Python and I want to try to make a simple personal exercise, something like a simple file compression.  I'm just wondering how will I be able to write it in my Python code to "read" from a text file?  For example, my simple Python program will ask what file that will be compress or uncompress?  Please consider the display:

- - - < s n i p > - - -

Please enter the filename to compress:

or

Please enter the filename to uncompress:

- - - < s n i p > - - -

So, it will "read" the filename that has been entered and will look for it.  If found, it will "write" to the same filename but if not, it will just prompt: "Please try again."

Second, I don't know if this was already been posted but I want to make a simple "text menu" in order to choose what functions/sub-programs shall be executed.  My problem is, how will I "ignore" the wrong type of choices?  Please consider my simple text menu below:

- - - < s n i p > - - -

- MY SIMPLE PROGRAM -

[1] Sub-program 1
[2] Sub-program 2
[3] Sub-program 3
[4] Sub-program 4
[5] Sub-program 5
[Q/q] Exit

Please enter your choice:

- - - < s n i p > - - -

If the "choice" is any character except "Q or q", it should not supposedly "exit" from the main program but rather it will just "ignore" or will not accept the "inputted" character or probably will display first an error message something like "Wrong input. Please try again." and the cursor will go back to the "choices".

The problem with input() is it will exit from the main program and display some errors if the "inputted" choice is not an integer.  Likewise with raw_input(), the opposite of input().

Last but not the least, what is "gotoxy" of Pascal in Python?

Thank you very much...

God bless you all...

__________________________________
www.edsamail.com