Allow _ for generating expressions

This commit is contained in:
Benjamin Bertrand 2016-01-17 17:51:12 +03:00
parent 602fd12b1e
commit 2b98d0e364

View File

@ -27,7 +27,7 @@ class RdExpression(object):
:param conditions: condition on variables (/!\ variables need to be in brackets {}) :param conditions: condition on variables (/!\ variables need to be in brackets {})
""" """
self._form = form self._form = self.mod_underscores(form)
self._conditions = conditions self._conditions = conditions
self._letters = self.get_letters() self._letters = self.get_letters()
@ -70,6 +70,20 @@ class RdExpression(object):
return varia return varia
def mod_underscores(self, form):
""" Transform underscores of string to {...} forme with capital letters
:param form: the form string with _ to replace
:returns: the string with _ replaced
"""
i = 64
new_form = form
while "_" in new_form:
i += 1
new_form = new_form.replace("_", "{"+chr(i)+"}",1)
return new_form
def __call__(self, val_min = -10, val_max = 10): def __call__(self, val_min = -10, val_max = 10):
"""RdExpression once it is initiate act like a function which create random expressions. """RdExpression once it is initiate act like a function which create random expressions.