SlideShare a Scribd company logo
1 of 8
Download to read offline
Menu.py a script of scripts.

I am constantly forgetting the exact paths and command structure for the various scripts I have written,
and I have some standard ways I run them. So, I created a script of scripts that I use to access them.
The program menu.py reads a comma delimited file and creates a menu that can then be navigated with
relative ease. For now I have kept it fairly simple.

I log in and type menu




This is a shell script that calls my menu.py script and is stored in my path so I can execute it from
anywhere.
The script truncates the name and description to keep things clean.

If I choose 6 to generate a 12 character password:
When I hit enter the screen clears and I am taken back to the menu.
Entering “n” at the main menu takes me to the next menu.




But entering “n” on this menu gives me an error.
Pressing enter again clears the screen and takes me back to the menu I was on.

Entering “p” takes me back one page.
And entering “q” at any menu takes me out of the program.

The shell script looks like this:
james@coenj-suse1:~> cat bin/menu
#!/usr/bin/sh
cd Python/etc
python menu.py

Note the script first cd's to the location I have stored menu.py. This is because the menu.dat file that
stores my script information is stored in the same directory as the menu.py script itself.
james@coenj-suse1:~/Python/etc> ls menu*
menu.dat menu.py

Here is a look at the menu.dat file:




Note the file is comma delimited and each text field is enclosed in double quotation marks. The first
field is the name you want displayed on the menu. The second is the command and path to execute the
script (in this case python <full path and arguments for script>). It should work just as well with shell
scripts by using sh in place of python. The last field is a short description (remember the menu.py
script will truncate the name and description).

The following is the source code for the menu.py script.
#!/usr/bin/python
#---------------------------------------------------------------#
# menu.py                                            #
# Created 2009.10.27                                      #
# By James D. Coen Sr                                       #
# This program reads a file that contains a list of programs #
# and then creates a menu based upon that list. The user can #
# then select a program to execute.                            #
# The layout of the file is as follows:                       #
# <"program name">,<"full execution path">,<"description">        #
#---------------------------------------------------------------#

import sys, os, csv

# Menu data file relative to script is menu.dat
myMenu = {} # create our menu
# index is count: program name, path, description
menuFile = os.path.join(os.path.abspath(os.curdir) + os.sep + 'menu.dat')

def truncString(inStr, max=20):
  # max size defaults to 20 characters
  i=0
  outStr = ''
  for let in inStr:
      if i < max:
         outStr = outStr + let
      else:
         break
      i=i+1
  return outStr

def genMenu():
  # limit to 10 programs per page
  pglim = 10
  retVal = 0
  page = 1
  pages = 1
  max = 0
  fp = open(menuFile, 'rb')
  csvFile = csv.reader(fp, delimiter=',', quotechar='"')
  for line in csvFile:
     max = max + 1
     myMenu[max] = [line[0], line[1], line[2]]
  pages = pages + (max / pglim)
  while page in range(1, pages+1):
     count = 0
     print '------------------------------------------------------------'
     print '              My Python Scripts Menu                       '
     print '                  Page {0:2d} of {1:2d} '.format(page,pages)
     for id, vals in myMenu.items():
        if (id / pglim + 1) == page:
           prog = truncString(vals[0], 20)
           dscr = truncString(vals[2], 30)
           print ' {0:2d}) {1:20s} {2:25s}'.format(id, prog, dscr)
count = count + 1
print
if pages == 1:
   print 'Choose the number corresponding to your choice'
elif pages > 1 and pages == page:
   print 'Choose the number corresponding to your choice or '
   print 'p/P for previous to change pages'
elif pages > 1 and pages != page and page > 1:
   print 'Choose the number corresponding to your choice or '
   print 'p/P for previous n/N for next to change pages'
else:
   print 'Choose the number corresponding to your choice or '
   print 'n/N for next to change pages'
print ' or enter q/Q to quit'
print '------------------------------------------------------------'
choice = raw_input('                    Enter your choice: ')
if choice.lower() == 'n' and pages > 1 and page != pages:
   # next page
   print ''
   page = page + 1
   sys.stdout.write(os.popen('clear').read()) # clear screen
   retVal = 0
elif choice.lower() == 'p' and pages > 1 and page != 1:
   # previous page
   print ''
   page = page - 1
   sys.stdout.write(os.popen('clear').read()) # clear screen
   retVal = 0
elif choice.lower() == 'q':
   # chose to quit
   print 'Exiting...'
   retVal = -1
   break
else:
   try:
      choice = int(choice)
      if choice not in range(1, count+1):
         print 'Invalid selection...'
         retVal = 0
         jnk = raw_input('Press enter to continue.')
         sys.stdout.write(os.popen('clear').read()) # clear screen
      else:
         sys.stdout.write(os.popen('clear').read()) # clear screen
         print 'Executing %s ...'%(myMenu[choice][1])
         print
         err = os.system(myMenu[choice][1])
         if err != 0:
            print 'Return Value: ' + str(err)
         print
retVal = 0
             jnk = raw_input('Press enter to continue.')
             sys.stdout.write(os.popen('clear').read()) # clear screen
       except:
          print 'Invalid selection...'
          retVal = 0
          jnk = raw_input('Press enter to continue.')
          sys.stdout.write(os.popen('clear').read()) # clear screen
  return retVal

menuOpt = 0
while menuOpt == 0:
  sys.stdout.write(os.popen('clear').read()) # clear screen
  menuOpt = genMenu()

sys.stdout.write(os.popen('clear').read()) # clear screen

Hopefully you will find this little menu program useful.

More Related Content

What's hot

Using the Command Line with Magento
Using the Command Line with MagentoUsing the Command Line with Magento
Using the Command Line with MagentoMatthew Haworth
 
Intro to OAuth
Intro to OAuthIntro to OAuth
Intro to OAuthmfrost503
 
Beware: Sharp Tools
Beware: Sharp ToolsBeware: Sharp Tools
Beware: Sharp Toolschrismdp
 
Node.js - Demnächst auf einem Server in Ihrer Nähe
Node.js - Demnächst auf einem Server in Ihrer NäheNode.js - Demnächst auf einem Server in Ihrer Nähe
Node.js - Demnächst auf einem Server in Ihrer NäheRalph Winzinger
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentationMartin McBride
 
dplyr and torrents from cpasbien
dplyr and torrents from cpasbiendplyr and torrents from cpasbien
dplyr and torrents from cpasbienRomain Francois
 
R で解く FizzBuzz 問題
R で解く FizzBuzz 問題R で解く FizzBuzz 問題
R で解く FizzBuzz 問題Kosei ABE
 
Torne seu código legível com enums | Cocoa heads 2018 fortaleza - Ramires Mor...
Torne seu código legível com enums | Cocoa heads 2018 fortaleza - Ramires Mor...Torne seu código legível com enums | Cocoa heads 2018 fortaleza - Ramires Mor...
Torne seu código legível com enums | Cocoa heads 2018 fortaleza - Ramires Mor...Ramires Moreira
 
Scroll pHAT HD に美咲フォント
Scroll pHAT HD に美咲フォントScroll pHAT HD に美咲フォント
Scroll pHAT HD に美咲フォントYuriko IKEDA
 
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014Puppet
 
言語の設計判断
言語の設計判断言語の設計判断
言語の設計判断nishio
 
Nomethoderror talk
Nomethoderror talkNomethoderror talk
Nomethoderror talkJan Berdajs
 
Total World Domination with i18n (es)
Total World Domination with i18n (es)Total World Domination with i18n (es)
Total World Domination with i18n (es)Zé Fontainhas
 
7b615dc2-ba86-4ecd-8b1f-d0d32de89a0c-160302154344
7b615dc2-ba86-4ecd-8b1f-d0d32de89a0c-1603021543447b615dc2-ba86-4ecd-8b1f-d0d32de89a0c-160302154344
7b615dc2-ba86-4ecd-8b1f-d0d32de89a0c-160302154344Branislav Simandel
 

What's hot (20)

Using the Command Line with Magento
Using the Command Line with MagentoUsing the Command Line with Magento
Using the Command Line with Magento
 
Intro to OAuth
Intro to OAuthIntro to OAuth
Intro to OAuth
 
Pop3ck sh
Pop3ck shPop3ck sh
Pop3ck sh
 
TerminalでTwitter
TerminalでTwitterTerminalでTwitter
TerminalでTwitter
 
Beware: Sharp Tools
Beware: Sharp ToolsBeware: Sharp Tools
Beware: Sharp Tools
 
Node.js - Demnächst auf einem Server in Ihrer Nähe
Node.js - Demnächst auf einem Server in Ihrer NäheNode.js - Demnächst auf einem Server in Ihrer Nähe
Node.js - Demnächst auf einem Server in Ihrer Nähe
 
Devtools Tips & Tricks
Devtools Tips & TricksDevtools Tips & Tricks
Devtools Tips & Tricks
 
Yahoo! JAPANとKotlin
Yahoo! JAPANとKotlinYahoo! JAPANとKotlin
Yahoo! JAPANとKotlin
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentation
 
dplyr and torrents from cpasbien
dplyr and torrents from cpasbiendplyr and torrents from cpasbien
dplyr and torrents from cpasbien
 
JavaScript patterns
JavaScript patternsJavaScript patterns
JavaScript patterns
 
R で解く FizzBuzz 問題
R で解く FizzBuzz 問題R で解く FizzBuzz 問題
R で解く FizzBuzz 問題
 
Torne seu código legível com enums | Cocoa heads 2018 fortaleza - Ramires Mor...
Torne seu código legível com enums | Cocoa heads 2018 fortaleza - Ramires Mor...Torne seu código legível com enums | Cocoa heads 2018 fortaleza - Ramires Mor...
Torne seu código legível com enums | Cocoa heads 2018 fortaleza - Ramires Mor...
 
Scroll pHAT HD に美咲フォント
Scroll pHAT HD に美咲フォントScroll pHAT HD に美咲フォント
Scroll pHAT HD に美咲フォント
 
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
 
言語の設計判断
言語の設計判断言語の設計判断
言語の設計判断
 
Nomethoderror talk
Nomethoderror talkNomethoderror talk
Nomethoderror talk
 
Android taipei 20160225 淺談closure
Android taipei 20160225   淺談closureAndroid taipei 20160225   淺談closure
Android taipei 20160225 淺談closure
 
Total World Domination with i18n (es)
Total World Domination with i18n (es)Total World Domination with i18n (es)
Total World Domination with i18n (es)
 
7b615dc2-ba86-4ecd-8b1f-d0d32de89a0c-160302154344
7b615dc2-ba86-4ecd-8b1f-d0d32de89a0c-1603021543447b615dc2-ba86-4ecd-8b1f-d0d32de89a0c-160302154344
7b615dc2-ba86-4ecd-8b1f-d0d32de89a0c-160302154344
 

Similar to Menu.py Script

Pres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfPres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfRamziFeghali
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdfsrxerox
 
03 Geographic scripting in uDig - halfway between user and developer
03 Geographic scripting in uDig - halfway between user and developer03 Geographic scripting in uDig - halfway between user and developer
03 Geographic scripting in uDig - halfway between user and developerAndrea Antonello
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabMohan Raj
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...Yashpatel821746
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Yashpatel821746
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...Yashpatel821746
 
Programming python quick intro for schools
Programming python quick intro for schoolsProgramming python quick intro for schools
Programming python quick intro for schoolsDan Bowen
 
Linux Basic commands for beginners-@OneMento
Linux Basic commands for beginners-@OneMentoLinux Basic commands for beginners-@OneMento
Linux Basic commands for beginners-@OneMentoBohar Singh
 
Assignment no39
Assignment no39Assignment no39
Assignment no39Jay Patel
 
PART 3: THE SCRIPTING COMPOSER AND PYTHON
PART 3: THE SCRIPTING COMPOSER AND PYTHONPART 3: THE SCRIPTING COMPOSER AND PYTHON
PART 3: THE SCRIPTING COMPOSER AND PYTHONAndrea Antonello
 
How fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practiceHow fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practiceTobias Pfeiffer
 
Basic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.comBasic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.comAkanchha Agrawal
 
ANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptxANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptxjeyel85227
 

Similar to Menu.py Script (20)

python codes
python codespython codes
python codes
 
Python basics
Python basicsPython basics
Python basics
 
Pres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfPres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdf
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdf
 
First c program
First c programFirst c program
First c program
 
Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
 
03 Geographic scripting in uDig - halfway between user and developer
03 Geographic scripting in uDig - halfway between user and developer03 Geographic scripting in uDig - halfway between user and developer
03 Geographic scripting in uDig - halfway between user and developer
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
 
Design problem
Design problemDesign problem
Design problem
 
Programming python quick intro for schools
Programming python quick intro for schoolsProgramming python quick intro for schools
Programming python quick intro for schools
 
Linux Basic commands for beginners-@OneMento
Linux Basic commands for beginners-@OneMentoLinux Basic commands for beginners-@OneMento
Linux Basic commands for beginners-@OneMento
 
Assignment no39
Assignment no39Assignment no39
Assignment no39
 
Cc code cards
Cc code cardsCc code cards
Cc code cards
 
PART 3: THE SCRIPTING COMPOSER AND PYTHON
PART 3: THE SCRIPTING COMPOSER AND PYTHONPART 3: THE SCRIPTING COMPOSER AND PYTHON
PART 3: THE SCRIPTING COMPOSER AND PYTHON
 
How fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practiceHow fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practice
 
Basic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.comBasic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.com
 
ANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptxANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptx
 

More from cfministries

Py Die R E A D M E
Py Die  R E A D M EPy Die  R E A D M E
Py Die R E A D M Ecfministries
 
Elemental Christianity
Elemental  ChristianityElemental  Christianity
Elemental Christianitycfministries
 
Example Stream Setup
Example  Stream  SetupExample  Stream  Setup
Example Stream Setupcfministries
 
Peering Through The Mercy Seat
Peering Through The Mercy SeatPeering Through The Mercy Seat
Peering Through The Mercy Seatcfministries
 
Apostolic Private Eye
Apostolic  Private  EyeApostolic  Private  Eye
Apostolic Private Eyecfministries
 
Do You Make Jesus Sick
Do You Make  Jesus SickDo You Make  Jesus Sick
Do You Make Jesus Sickcfministries
 
Why Wait Get It Now
Why Wait    Get It NowWhy Wait    Get It Now
Why Wait Get It Nowcfministries
 
The Mind Of God ( Part 5)
The  Mind Of  God ( Part 5)The  Mind Of  God ( Part 5)
The Mind Of God ( Part 5)cfministries
 
The Mind Of God ( Part 4)
The  Mind Of  God ( Part 4)The  Mind Of  God ( Part 4)
The Mind Of God ( Part 4)cfministries
 
The Mind Of God ( Part 3)
The  Mind Of  God ( Part 3)The  Mind Of  God ( Part 3)
The Mind Of God ( Part 3)cfministries
 
The Mind Of God ( Part 2)
The  Mind Of  God ( Part 2)The  Mind Of  God ( Part 2)
The Mind Of God ( Part 2)cfministries
 
The Mind Of God ( Part 1)
The  Mind Of  God ( Part 1)The  Mind Of  God ( Part 1)
The Mind Of God ( Part 1)cfministries
 

More from cfministries (17)

Grade Statistics
Grade StatisticsGrade Statistics
Grade Statistics
 
R P G Generator
R P G  GeneratorR P G  Generator
R P G Generator
 
 
Py Die R E A D M E
Py Die  R E A D M EPy Die  R E A D M E
Py Die R E A D M E
 
Dealing W Spam
Dealing W SpamDealing W Spam
Dealing W Spam
 
Elemental Christianity
Elemental  ChristianityElemental  Christianity
Elemental Christianity
 
Example Stream Setup
Example  Stream  SetupExample  Stream  Setup
Example Stream Setup
 
Peering Through The Mercy Seat
Peering Through The Mercy SeatPeering Through The Mercy Seat
Peering Through The Mercy Seat
 
Apostolic Private Eye
Apostolic  Private  EyeApostolic  Private  Eye
Apostolic Private Eye
 
Do You Make Jesus Sick
Do You Make  Jesus SickDo You Make  Jesus Sick
Do You Make Jesus Sick
 
Why Wait Get It Now
Why Wait    Get It NowWhy Wait    Get It Now
Why Wait Get It Now
 
The Mind Of God ( Part 5)
The  Mind Of  God ( Part 5)The  Mind Of  God ( Part 5)
The Mind Of God ( Part 5)
 
The Mind Of God ( Part 4)
The  Mind Of  God ( Part 4)The  Mind Of  God ( Part 4)
The Mind Of God ( Part 4)
 
5 Questions
5  Questions5  Questions
5 Questions
 
The Mind Of God ( Part 3)
The  Mind Of  God ( Part 3)The  Mind Of  God ( Part 3)
The Mind Of God ( Part 3)
 
The Mind Of God ( Part 2)
The  Mind Of  God ( Part 2)The  Mind Of  God ( Part 2)
The Mind Of God ( Part 2)
 
The Mind Of God ( Part 1)
The  Mind Of  God ( Part 1)The  Mind Of  God ( Part 1)
The Mind Of God ( Part 1)
 

Menu.py Script

  • 1. Menu.py a script of scripts. I am constantly forgetting the exact paths and command structure for the various scripts I have written, and I have some standard ways I run them. So, I created a script of scripts that I use to access them. The program menu.py reads a comma delimited file and creates a menu that can then be navigated with relative ease. For now I have kept it fairly simple. I log in and type menu This is a shell script that calls my menu.py script and is stored in my path so I can execute it from anywhere.
  • 2. The script truncates the name and description to keep things clean. If I choose 6 to generate a 12 character password:
  • 3. When I hit enter the screen clears and I am taken back to the menu. Entering “n” at the main menu takes me to the next menu. But entering “n” on this menu gives me an error.
  • 4. Pressing enter again clears the screen and takes me back to the menu I was on. Entering “p” takes me back one page.
  • 5. And entering “q” at any menu takes me out of the program. The shell script looks like this: james@coenj-suse1:~> cat bin/menu #!/usr/bin/sh cd Python/etc python menu.py Note the script first cd's to the location I have stored menu.py. This is because the menu.dat file that stores my script information is stored in the same directory as the menu.py script itself. james@coenj-suse1:~/Python/etc> ls menu* menu.dat menu.py Here is a look at the menu.dat file: Note the file is comma delimited and each text field is enclosed in double quotation marks. The first field is the name you want displayed on the menu. The second is the command and path to execute the script (in this case python <full path and arguments for script>). It should work just as well with shell scripts by using sh in place of python. The last field is a short description (remember the menu.py script will truncate the name and description). The following is the source code for the menu.py script. #!/usr/bin/python #---------------------------------------------------------------# # menu.py # # Created 2009.10.27 # # By James D. Coen Sr #
  • 6. # This program reads a file that contains a list of programs # # and then creates a menu based upon that list. The user can # # then select a program to execute. # # The layout of the file is as follows: # # <"program name">,<"full execution path">,<"description"> # #---------------------------------------------------------------# import sys, os, csv # Menu data file relative to script is menu.dat myMenu = {} # create our menu # index is count: program name, path, description menuFile = os.path.join(os.path.abspath(os.curdir) + os.sep + 'menu.dat') def truncString(inStr, max=20): # max size defaults to 20 characters i=0 outStr = '' for let in inStr: if i < max: outStr = outStr + let else: break i=i+1 return outStr def genMenu(): # limit to 10 programs per page pglim = 10 retVal = 0 page = 1 pages = 1 max = 0 fp = open(menuFile, 'rb') csvFile = csv.reader(fp, delimiter=',', quotechar='"') for line in csvFile: max = max + 1 myMenu[max] = [line[0], line[1], line[2]] pages = pages + (max / pglim) while page in range(1, pages+1): count = 0 print '------------------------------------------------------------' print ' My Python Scripts Menu ' print ' Page {0:2d} of {1:2d} '.format(page,pages) for id, vals in myMenu.items(): if (id / pglim + 1) == page: prog = truncString(vals[0], 20) dscr = truncString(vals[2], 30) print ' {0:2d}) {1:20s} {2:25s}'.format(id, prog, dscr)
  • 7. count = count + 1 print if pages == 1: print 'Choose the number corresponding to your choice' elif pages > 1 and pages == page: print 'Choose the number corresponding to your choice or ' print 'p/P for previous to change pages' elif pages > 1 and pages != page and page > 1: print 'Choose the number corresponding to your choice or ' print 'p/P for previous n/N for next to change pages' else: print 'Choose the number corresponding to your choice or ' print 'n/N for next to change pages' print ' or enter q/Q to quit' print '------------------------------------------------------------' choice = raw_input(' Enter your choice: ') if choice.lower() == 'n' and pages > 1 and page != pages: # next page print '' page = page + 1 sys.stdout.write(os.popen('clear').read()) # clear screen retVal = 0 elif choice.lower() == 'p' and pages > 1 and page != 1: # previous page print '' page = page - 1 sys.stdout.write(os.popen('clear').read()) # clear screen retVal = 0 elif choice.lower() == 'q': # chose to quit print 'Exiting...' retVal = -1 break else: try: choice = int(choice) if choice not in range(1, count+1): print 'Invalid selection...' retVal = 0 jnk = raw_input('Press enter to continue.') sys.stdout.write(os.popen('clear').read()) # clear screen else: sys.stdout.write(os.popen('clear').read()) # clear screen print 'Executing %s ...'%(myMenu[choice][1]) print err = os.system(myMenu[choice][1]) if err != 0: print 'Return Value: ' + str(err) print
  • 8. retVal = 0 jnk = raw_input('Press enter to continue.') sys.stdout.write(os.popen('clear').read()) # clear screen except: print 'Invalid selection...' retVal = 0 jnk = raw_input('Press enter to continue.') sys.stdout.write(os.popen('clear').read()) # clear screen return retVal menuOpt = 0 while menuOpt == 0: sys.stdout.write(os.popen('clear').read()) # clear screen menuOpt = genMenu() sys.stdout.write(os.popen('clear').read()) # clear screen Hopefully you will find this little menu program useful.