new to python

Discussion in 'Python' started by Chris Patton, Oct 10, 2004.

  1. Chris Patton

    Chris Patton Guest

    I need to make several user-defined objects for a program I'm making.
    I know that one way is to use the exec statement (i.e. exec
    'raw_input() = "cheese"'), but it can get very visually cluttered at
    times.
    i.e. exec raw_input()+num+'={"I":'+b+','+am+':"just","fine":1}'

    Does anyone know a different way I can do this? I need to do this to
    define a dictionary, but a general method for all objects would be
    better.

    Thanks for any help!
    ---
     
    Chris Patton, Oct 10, 2004
    #1
    1. Advertisements

  2. Hi Chris. Your question has been discussed by several people already the
    last time you answered it. Please do us the courtesy of reading those
    answers before repeating your question.

    Also, my short answer to your question is: don't do that! I really have
    to question why you need to set variables in local or global scope
    rather than just setting items in a dictionary. Why?
     
    Michael Hoffman, Oct 10, 2004
    #2
    1. Advertisements

  3. Chris Patton

    Mitja Guest

    Don't go for global user-defined variables - it's hard to control and a big security risk. A far better thing to do would be
    something like

    usersVars={}
    usersVars[raw_input()]= {4:'sdf', 'foo':'bar'}
     
    Mitja, Oct 10, 2004
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.