Creating a Simple User Interface for a Function

Terry Reedy tjreedy at udel.edu
Fri Jul 26 01:46:44 CEST 2013


Some additional comments.

On 7/25/2013 7:00 PM, Terry Reedy wrote:
> On 7/25/2013 4:58 PM, CTSB01 wrote:
>
>> 1) I decided to use Python 2.7, and I will be sure to specify this in
>> all future threads.
>
> Given that you are not using any libraries, let alone one that does not
> run on Python 3, I strongly recommend using the latest version (3.3).

It would be pretty easy to make your simple code run on both 3.x and 
2.6/7. Start your file (after any docstring or initial comment) with
from __future__ import division, print_function

Use "except XyxError as e:" instead of "except XyzError, e:".

> If users start the program at a command line, the core of an input
> function would be
>    numbers = input('Enter digits: ')  # see below
> You would need a more elaborate prompt printed first, and input checking
> with the request repeated if the input does not pass the check.

# To run on both 2.x and 3.x, put this after the __future__ import:
try:
     input = raw_input
except NameError:
     pass

>> I'd like to be
>> able to run send a .exe file that the user can just open up and use
>> with no further setup.
>
> There are programs that will package your code with an interpreter.

A Python pre-built binary is overkill for such a small function. The 
reason for doing so, packaging all dependencies together, does not 
apply. Any binary is limited to what machines it will run on.

> do give people the option to get just the program without installing a
> duplicate interpreter.

A Python file, especially if designed to run on 2.6, will run on most 
any recent installation.

-- 
Terry Jan Reedy




More information about the Python-list mailing list