new to python

C

Chris Patton

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!
---
 
M

Michael Hoffman

Chris said:
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}'

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?
 
M

Mitja

Chris said:
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.

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'}
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top