Re: How do I convert arithemtic string (like "2+2") to a number?

2005-02-06 Thread Michael Spencer
John J. Lee wrote: "Adomas" <[EMAIL PROTECTED]> writes: Well, a bit more secure would be eval(expression, {'__builtins__': {}}, {}) or alike. Don't believe this without (or even with ;-) very careful thought, anyone. Google for rexec. John This module provides a more systematic way to set up res

Re: How do I convert arithemtic string (like "2+2") to a number?

2005-02-06 Thread John J. Lee
"Adomas" <[EMAIL PROTECTED]> writes: > Well, a bit more secure would be > > eval(expression, {'__builtins__': {}}, {}) > > or alike. Don't believe this without (or even with ;-) very careful thought, anyone. Google for rexec. John -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I convert arithemtic string (like "2+2") to a number?

2005-02-06 Thread Adomas
Well, a bit more secure would be eval(expression, {'__builtins__': {}}, {}) or alike. -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I convert arithemtic string (like "2+2") to a number?

2005-02-06 Thread Reinhold Birkenfeld
Michael Hartl wrote: > Adam brings up a good point: eval is a very general function which > evaluates an arbitrary Python expression. As a result, it (and its > close cousin exec) should be used with caution if security is an issue. To get a secure eval for simple mathematical expressions, it sho

Re: How do I convert arithemtic string (like "2+2") to a number?

2005-02-05 Thread Michael Hartl
Adam brings up a good point: eval is a very general function which evaluates an arbitrary Python expression. As a result, it (and its close cousin exec) should be used with caution if security is an issue. Michael -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I convert arithemtic string (like "2+2") to a number?

2005-02-05 Thread Adam DePrince
On Sat, 2005-02-05 at 17:11, Michael Hartl wrote: > Use the eval function: > > >>> eval("30/(6+9)") > 2 > > Michael Sure, if you trust the source of the string you are evaluating. If this is a form submission on your web site, be wary of the nefarious user who might submit to you: commands.get

Re: How do I convert arithemtic string (like "2+2") to a number?

2005-02-05 Thread Arvid Andersson
On Sat, Feb 05, 2005 at 02:11:07PM -0800, Michael Hartl wrote: > Use the eval function: > > >>> eval("30/(6+9)") > 2 > Thanks, just what I was looking for! -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I convert arithemtic string (like "2+2") to a number?

2005-02-05 Thread Michael Hartl
Use the eval function: >>> eval("30/(6+9)") 2 Michael -- http://mail.python.org/mailman/listinfo/python-list

How do I convert arithemtic string (like "2+2") to a number?

2005-02-05 Thread Arvid Andersson
Hello, I need to convert a string to a number, but the string can contain +,-,* and / as well as parenthesis. For example, if I have the string "30/(6+9)" I would like a function that returned the number 2. I actually wrote a java function that did this a couple of years ago, in school, as an e