Ich poste hier mal die [die Antwort von DJP][1] auf meine Frage aus dem Tex.stackexchange forum:
A lot of packages don't "play well" with the sagetex package. This appears to be one such package in that it prevents you from typing things in the natural way you tried in your code. One approach is to take advantage of sagetex and Python to avoid even having to use the ifthen package. But if you want to use that package then you can have sagetex insert the command as a string. This solution doesn't seem particularly natural but I don't know of a better way.
\documentclass{article}
\usepackage{sagetex}
\usepackage{ifthen}
\begin{document}
\begin{sagesilent}
var('x')
f = x^2
output = r""
if f(2)>0:
output += "a"
else:
output += "b"
output1 = r"\ifthenelse{%s>%s}{a}{b}"%(f(2),0)
\end{sagesilent}
One way to handle the problem is to process it with sagetex to get\\
\sagestr{output}\\
and another way is to insert the command as a string\\
\sagestr{output1}
\end{document}
[1]: http://tex.stackexchange.com/a/267828