r wrote:
On Aug 28, 8:43 pm, Anny Mous wrote:
It isn't irrational to have a healthy caution towards eval.
Ignorance is never an excuse for stupidity. No caution is needed if
you know how to properly use eval. You can't shoot yourself in the
foot without first pulling the trigger.
Apart from
On Aug 28, 8:43 pm, Anny Mous wrote:
> It isn't irrational to have a healthy caution towards eval.
Ignorance is never an excuse for stupidity. No caution is needed if
you know how to properly use eval. You can't shoot yourself in the
foot without first pulling the trigger.
> Apart from the secur
r wrote:
> Abviously the OP is a python baby noob and casting your irrational
> fear (and many others irrational fears) of eval
It isn't irrational to have a healthy caution towards eval.
Apart from the security issues, running code in eval takes a massive
performance hit. Its about ten times s
En Fri, 28 Aug 2009 01:50:37 -0300, Xavier Ho
escribió:
On Fri, Aug 28, 2009 at 2:35 PM, Ben Finney
wrote:
op_funcs = {
'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': operator.div,
}
op_prompt = "Select an operator ({}):".format(','.j
On Fri, 28 Aug 2009, Ben Finney wrote:
> Duke Normandin writes:
>
> > Hey
> >
> > I'm a Python noob
> >
> > So far so good!
> >
> > I've written the following:
> >
> > num1 = raw_input('Enter the first number: ')
> > num2 = raw_input('Enter the second number: ')
> > op = raw_input('Select
On Thu, 27 Aug 2009, r wrote:
> On Aug 27, 10:52 pm, Duke Normandin wrote:
> > How do I convert the contents of "op" from a string to an actual
> > arithmetic operator? eval() does not seem to be the answer. TIA!
>
>
> Try this..
>
> >>> op = '+'
> >>> one = '1'
> >>> two = '2'
> >>> one+op+two
>
On Thu, 27 Aug 2009, Stephen Hansen wrote:
> >
> > num1 = raw_input('Enter the first number: ')
> > num2 = raw_input('Enter the second number: ')
> > op = raw_input('Select one of the following [+-*/]: ')
> > print 'The answer is: ', int(num1), eval(op), int(num2)
> >
>
> > I would use the following approach:
>
> Abviously the OP is a python baby noob and casting your irrational
> fear (and many others irrational fears) of eval at him is akin to
> tales of Chupacabras running a muck in the jungle sucking the blood
> from live goats in the twilight hours. I use e
On Aug 27, 11:35 pm, Ben Finney wrote:
> In general, ‘eval’ on unsanitised input is not the answer.
Yes i agree.
> I would use the following approach:
Abviously the OP is a python baby noob and casting your irrational
fear (and many others irrational fears) of eval at him is akin to
tales of Ch
On Fri, Aug 28, 2009 at 2:35 PM, Ben Finney
> wrote:
>import operator
>
>op_funcs = {
>'+': operator.add,
>'-': operator.sub,
>'*': operator.mul,
>'/': operator.div,
>}
>
>num_1 = int(raw_input('Enter the first number: '))
>num_2 = int(raw_i
Duke Normandin writes:
> Hey
>
> I'm a Python noob
>
> So far so good!
>
> I've written the following:
>
> num1 = raw_input('Enter the first number: ')
> num2 = raw_input('Enter the second number: ')
> op = raw_input('Select one of the following [+-*/]: ')
> print 'The answer is: ', int(n
>
> num1 = raw_input('Enter the first number: ')
> num2 = raw_input('Enter the second number: ')
> op = raw_input('Select one of the following [+-*/]: ')
> print 'The answer is: ', int(num1), eval(op), int(num2)
>
>
> How do I convert the contents of "op"
On Aug 27, 10:52 pm, Duke Normandin wrote:
> How do I convert the contents of "op" from a string to an actual
> arithmetic operator? eval() does not seem to be the answer. TIA!
Try this..
>>> op = '+'
>>> one = '1'
>>> two = '2'
>>> one+op+two
'1+2'
>>> eval(one+op+two)
3
you could also use s
On Fri, Aug 28, 2009 at 1:52 PM, Duke Normandin wrote:
> How do I convert the contents of "op" from a string to an actual
> arithmetic operator? eval() does not seem to be the answer. TIA!
Maybe you were looking for
print eval(num1 + op + num2) # it's a little ugly string concatenation.
Hm? (
Hey
I'm a Python noob
So far so good!
I've written the following:
num1 = raw_input('Enter the first number: ')
num2 = raw_input('Enter the second number: ')
op = raw_input('Select one of the following [+-*/]: ')
print 'The answer is: ', int(num1), eval(op), int(num2)
15 matches
Mail list logo