我想了解eval(),但沒有多少運氣。對用戶提供的集成函數使用「eval」?
我正在寫自己的數學庫,並試圖將集成納入庫。我需要幫助讓python將函數識別爲一系列變量,常量和運算符。我被告知,eval會做的伎倆,但我會怎麼去呢?
fofx = input ("Write your function of x here >")
def integrate (fofx):
#integration algorithm here
#input fofx and recognize it as f(x) to be integrated.
我已經嘗試了文檔,但這是有限的,我不知道如何我可以將它應用到我的函數進行評估。
'eval'在這裏沒有幫助。看看['ast'](http://docs.python.org/py3k/library/ast.html「抽象語法樹」) – 2012-04-01 16:58:09
那麼,你的問題是什麼? – Marcin 2012-04-01 16:58:26
你是說http://docs.python.org/library/functions.html#eval是有限的?有什麼不清楚這個鏈接? – Simon 2012-04-01 17:00:01