Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to pass mix of scalars and lists to function #22

Open
z0u opened this issue Dec 19, 2016 · 1 comment
Open

No way to pass mix of scalars and lists to function #22

z0u opened this issue Dec 19, 2016 · 1 comment

Comments

@z0u
Copy link
Contributor

z0u commented Dec 19, 2016

Lists are flattened, so there's no way to pass in an entire list as an argument to a function.

def f(xs, y):
     return sum(x + y for x in xs)

f([1,2,3], 2)
# 12

parser.evaluate("f(xs, y)", variables={"f": f, "xs": [1,2,3], "y": 2})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "py_expression_eval/__init__.py", line 494, in evaluate
    return self.parse(expr).evaluate(variables)
  File "py_expression_eval/__init__.py", line 138, in evaluate
    nstack.append(f(*n1))
TypeError: f() takes 2 positional arguments but 4 were given
@willstott101
Copy link

In this example you could use f(y, *xs) but of course it would still be impossible to have two lists as parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants