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

Example code in readme does not work with latest PyPI percol 0.2.1 #108

Open
hartwork opened this issue Jul 21, 2020 · 0 comments
Open

Example code in readme does not work with latest PyPI percol 0.2.1 #108

hartwork opened this issue Jul 21, 2020 · 0 comments

Comments

@hartwork
Copy link

hartwork commented Jul 21, 2020

Hi!

I would like to vote for for a new release. The readme changes merged from 4b28037 are not supported: Once I fix the sting IO import for Python 3 (#107) I get ImportError: cannot import name 'no_output' from 'percol.actions' for a good reason: It does not exist in release 0.2.1. Can we have a new release please please?

If anyone needs a version of the example that works with Python 3.7:

from io import StringIO
from percol import Percol
from percol.actions import action

@action()
def no_output(lines, percol):
    "ignore all output"
    pass

def main(candidates):
    si, so, se = StringIO(), StringIO(), StringIO()
    with Percol(
            actions=[no_output],
            descriptors={'stdin': si, 'stdout': so, 'stderr': se},
            candidates=iter(candidates)) as p:
        p.loop()
    if p.args_for_action is None:
        raise KeyboardInterrupt
    results = p.model_candidate.get_selected_results_with_index()
    return [r[0] for r in results]

if __name__ == "__main__":
    candidates = ['foo', 'bar', 'baz']
    results = main(candidates)
    print("You picked: {!r}".format(results))

Best, Sebastian

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

1 participant