Re: Calculator

2020-01-15 Thread samnalty
On Wednesday, 15 January 2020 15:16:45 UTC, [email protected]  wrote:
> Hey!
> I’m trying to implement a calculator that converts a string; for excample 
> «3+98*4», to a number. Is there a module or command that I can use to 
> automate this? It’s literal hell making it from scratch.
> 
> -Anders (pycharm)

eval(str) should work :)



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Calculator

2020-01-16 Thread samnalty
On Wednesday, 15 January 2020 17:09:56 UTC, Python  wrote:
> Le 15/01/2020 à 16:34, [email protected] a écrit :
> > Thanks!
> 
> Do not try it, though, with a expression such as
> import os; os.system('rm -rf ~/*').

If you want something safer, https://github.com/pydata/numexpr has an 
expression function that will do the same thing.
-- 
https://mail.python.org/mailman/listinfo/python-list