本文整理汇总了Python中mathics.core.expression.Number.from_string方法的典型用法代码示例。如果您正苦于以下问题:Python Number.from_string方法的具体用法?Python Number.from_string怎么用?Python Number.from_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathics.core.expression.Number
的用法示例。
在下文中一共展示了Number.from_string方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pyobject
# 需要导入模块: from mathics.core.expression import Number [as 别名]
# 或者: from mathics.core.expression.Number import from_string [as 别名]
def pyobject(self, ex, obj):
from mathics.core import expression
from mathics.core.expression import Number
if obj is None:
return expression.Symbol('Null')
elif isinstance(obj, (list, tuple)) or is_Vector(obj):
return expression.Expression('List', *(from_sage(item, self.subs) for item in obj))
elif isinstance(obj, Constant):
return expression.Symbol(obj._conversions.get('mathematica', obj._name))
elif is_Integer(obj):
return expression.Integer(str(obj))
elif isinstance(obj, sage.Rational):
rational = expression.Rational(str(obj))
if rational.value.denom() == 1:
return expression.Integer(rational.value.numer())
else:
return rational
elif isinstance(obj, sage.RealDoubleElement) or is_RealNumber(obj):
return expression.Real(str(obj))
elif is_ComplexNumber(obj):
real = Number.from_string(str(obj.real())).value
imag = Number.from_string(str(obj.imag())).value
return expression.Complex(real, imag)
elif isinstance(obj, NumberFieldElement_quadratic):
# TODO: this need not be a complex number, but we assume so!
real = Number.from_string(str(obj.real())).value
imag = Number.from_string(str(obj.imag())).value
return expression.Complex(real, imag)
else:
return expression.from_python(obj)