[Tutor] changing list index start
Francesco Loffredo
fal at libero.it
Sat Sep 11 13:04:05 CEST 2010
On 10/09/2010 23.36, Rance Hall wrote:
> I'm using the following function style I found on the net to create
> menus for a command line python script:
>
> def mainmenu():
> # the main menu
> todolist()
> mainmenuoptions = ['Clients','Jobs','Billing','Quotes','To Do
> Items','Employee','Exit']
> mainmenucalls = [clientsmenu, jobsmenu, billingmenu, quotesmenu,
> todomenu, empmenu, quit]
> for i,option in enumerate(mainmenuoptions):
> print('%s. %s' % (i, option))
> mainchoice = int(input('\nYour Choice? '))
> clearscreen(osname)
> mainmenucalls[mainchoice]()
> return
>
> It works well, but the first item is the list is item 0. This is
> normal in most computing situations, but because this index is part of
> the output It would be nice if the first item in the list is item 1.
>
> php provided a way to change this, but I can find no documentation
> that says python can do this as well.
I don't know of any way to change this, but I can think may ways to
bypass the "problem" or to make good use of it. For example:
mainmenuoptions = ["Main Menu:\n",
'Clients','Jobs','Billing','Quotes','To Do Items','Employee','Exit']
mainmenucalls = [do_nothing, clientsmenu, jobsmenu, billingmenu,
quotesmenu, todomenu, empmenu, quit]
def do_nothing()
pass
What about this?
Francesco
-------------- next part --------------
Nessun virus nel messaggio in uscita.
Controllato da AVG - www.avg.com
Versione: 9.0.851 / Database dei virus: 271.1.1/3126 - Data di rilascio: 09/10/10 09:08:00
More information about the Tutor
mailing list