Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52991 > unrolled thread
| Started by | Mohsen Pahlevanzadeh <mohsen@pahlevanzadeh.org> |
|---|---|
| First post | 2013-08-25 23:48 +0430 |
| Last post | 2013-08-26 19:43 +0430 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
python eval function Mohsen Pahlevanzadeh <mohsen@pahlevanzadeh.org> - 2013-08-25 23:48 +0430
Re: python eval function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-26 00:55 +0000
Re: python eval function Mohsen Pahlevanzadeh <mohsen@pahlevanzadeh.org> - 2013-08-26 19:43 +0430
| From | Mohsen Pahlevanzadeh <mohsen@pahlevanzadeh.org> |
|---|---|
| Date | 2013-08-25 23:48 +0430 |
| Subject | python eval function |
| Message-ID | <mailman.228.1377474113.19984.python-list@python.org> |
Dear all, eval doesn't run my code at the following link: http://stackoverflow.com/questions/18432198/eval-function-doesnt-work-in-python Thank you before your answer... --mohsen
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-08-26 00:55 +0000 |
| Message-ID | <521aa76a$0$29986$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #52991 |
On Sun, 25 Aug 2013 23:48:34 +0430, Mohsen Pahlevanzadeh wrote: > 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) -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Mohsen Pahlevanzadeh <mohsen@pahlevanzadeh.org> |
|---|---|
| Date | 2013-08-26 19:43 +0430 |
| Message-ID | <mailman.237.1377530050.19984.python-list@python.org> |
| In reply to | #52995 |
On Mon, 2013-08-26 at 00:55 +0000, Steven D'Aprano wrote: > On Sun, 25 Aug 2013 23:48:34 +0430, Mohsen Pahlevanzadeh wrote: > > > 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) > > > > -- > Steven 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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web