?
Solved

store commands

Posted on 2005-04-29
6
Medium Priority
?
220 Views
Last Modified: 2010-04-16
hi, i would like to ask how do i get all the commands that the user has input from a menu eg: 1 function do, 2 function test, 3 function go and store the functions into a file eg. Date    Time    do

   opt = raw_input("Enter Your Opt: ")
   opt = []
   print opt

   testfunc = {
   '1': do,
   '2': test,
   '3': go,
    }
   testfunc[opt]()
0
Comment
Question by:darrenteo82
3 Comments
 

Author Comment

by:darrenteo82
ID: 13899777
i tried to put the user inputs in a list but i get an error list is unhashable .... any ideas anyone ?
0
 
LVL 15

Accepted Solution

by:
mish33 earned 200 total points
ID: 13946863
If you want to keep all history in memory:

history = []
while program_runs:
  opt = raw_input("Enter Your Opt: ")
  history.append(opt)
  testfunc(opt)
log = file("log","w")
for opt in history:
  print >>log, opt

or just save along the execution:

log = file("log","w")
try:
  while program_runs:
    opt = raw_input("Enter Your Opt: ")
    print >>log, opt
    testfunc(opt)
finally:
  log.close()

Decorate prints with time on your taste.
0
 
LVL 17

Expert Comment

by:ramrom
ID: 13987606
darrenteo82 - does that answer your question?

Bob Gailer
Page Editor
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The really strange introduction Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Som…
Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question