store commands

Posted on 2005-04-29
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,
Question by:darrenteo82

    Author Comment

    i tried to put the user inputs in a list but i get an error list is unhashable .... any ideas anyone ?
    LVL 15

    Accepted Solution

    If you want to keep all history in memory:

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

    or just save along the execution:

    log = file("log","w")
      while program_runs:
        opt = raw_input("Enter Your Opt: ")
        print >>log, opt

    Decorate prints with time on your taste.
    LVL 17

    Expert Comment

    darrenteo82 - does that answer your question?

    Bob Gailer
    Page Editor

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    "The time has come," the Walrus said, "To talk of many things: Of sets--and lists--and dictionaries-- Of variable kinks-- And why you see it changing not-- And why so strange are strings." This part describes how variables and references (see …
    A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
    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…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now