python eval function

  • Thread starter Mohsen Pahlevanzadeh
  • Start date
S

Steven D'Aprano

Dear all,

eval doesn't run my code at the following link:
http://stackoverflow.com/questions/18432198/eval-function-doesnt-work-
in-python


Are you asking a question or just sharing a useful link?


Thank you before your answer...

What question do you want us to answer? The question on Stackoverflow has
already been answered correctly: there is no need to use eval (or exec)
for this basic task.

Also, you're not writing C code. Get rid of the semi-colons, they are
just a waste of time, and make you look like an incompetent programmer.

Using exec is not the right solution. That is unsafe, if the field name
and content come from a database or external input, your code now has a
*serious* Code Injection vulnerability. AND it is slow. So you have
written slow, unsafe code. Get rid of it, and use setattr like you have
already been told:

setattr(self, fieldName, fieldValue)
 
M

Mohsen Pahlevanzadeh

in-python


Are you asking a question or just sharing a useful link?




What question do you want us to answer? The question on Stackoverflow has
already been answered correctly: there is no need to use eval (or exec)
for this basic task.

Also, you're not writing C code. Get rid of the semi-colons, they are
just a waste of time, and make you look like an incompetent programmer.

Using exec is not the right solution. That is unsafe, if the field name
and content come from a database or external input, your code now has a
*serious* Code Injection vulnerability. AND it is slow. So you have
written slow, unsafe code. Get rid of it, and use setattr like you have
already been told:

setattr(self, fieldName, fieldValue)
I didn't post a useful link,i questioned my problem.Of course, At first
i put it @stackoverflow then post its link for the following idea:
1. collecting votes for me and someone answered.
2. If anyone have my question in future, can use it.
Thank you for answer.

--mohsen
 

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

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top