move __str__ from expression to renderable
This commit is contained in:
parent
6428ab2c9e
commit
bcd5643202
@ -427,7 +427,7 @@ class AbstractPolynom(Explicable):
|
||||
return ans
|
||||
|
||||
def replace_letter(self, letter):
|
||||
""" Replace the letter in the expression
|
||||
r""" Replace the letter in the expression
|
||||
|
||||
:param letter: the new letter.
|
||||
:returns: The expression with the new letter.
|
||||
|
@ -73,14 +73,6 @@ class Expression(Explicable):
|
||||
self.steal_history(exp)
|
||||
self._isExpression = 1
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
Overload str
|
||||
|
||||
If you want to changer render use Expression.set_render(...) or use tmp_render context manager.
|
||||
"""
|
||||
return self.STR_RENDER(self.postfix_tokens)
|
||||
|
||||
def simplify(self):
|
||||
""" Compute entirely the expression and return the result with .steps attribute """
|
||||
try:
|
||||
@ -177,7 +169,7 @@ class Expression(Explicable):
|
||||
|
||||
@classmethod
|
||||
def develop_steps(cls, tokenList):
|
||||
"""
|
||||
r"""
|
||||
From a list of tokens, it develops steps of each tokens and transpose it into steps respecting the stucture of the tokenList.
|
||||
|
||||
It try to use 'explain' method for every tokens. After using this methode, tokens becom amnesiac.
|
||||
@ -186,8 +178,14 @@ class Expression(Explicable):
|
||||
>>> e1 = e.simplify()
|
||||
>>> f = Expression('3*4+5')
|
||||
>>> f1 = f.simplify()
|
||||
>>> Expression.develop_steps([e1, f1, op.add])
|
||||
>>> dev_steps = Expression.develop_steps([e1, f1, op.add])
|
||||
>>> dev_steps
|
||||
[< Step [1, 2, +, 3, 4, *, 5, +, +]>, < Step [3, 12, 5, +, +]>, < Step [3, 17, +]>]
|
||||
>>> for i in dev_steps:
|
||||
... print(i)
|
||||
1 + 2 + 3 \times 4 + 5
|
||||
3 + 12 + 5
|
||||
3 + 17
|
||||
>>> e = Expression('1+2')
|
||||
>>> e1 = e.simplify()
|
||||
>>> f = Expression('3*4+5')
|
||||
|
@ -76,6 +76,14 @@ class Renderable(object):
|
||||
"""
|
||||
self.postfix_tokens = pstf_tokens
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
Overload str
|
||||
|
||||
If you want to changer render use Expression.set_render(...) or use tmp_render context manager.
|
||||
"""
|
||||
return self.STR_RENDER(self.postfix_tokens)
|
||||
|
||||
def __repr__(self):
|
||||
return "< {cls} {pstf_tokens}>".format(
|
||||
cls = str(self.__class__).split('.')[-1][:-2],
|
||||
|
@ -26,7 +26,7 @@ class Step(Renderable):
|
||||
\\frac{ 6 }{ 5 }
|
||||
>>> with Step.tmp_render():
|
||||
... for i in exp.simplify().explain():
|
||||
... print(i)
|
||||
... print(repr(i))
|
||||
< Step [2, 3, 5, /, *]>
|
||||
< Step [3, 5, /, 2, *]>
|
||||
< Step [3, 2, *, 5, /]>
|
||||
|
Loading…
Reference in New Issue
Block a user