What is the difference between concurrent.futures and asyncio.futures?

The asyncio documentation covers the differences: class asyncio.Future(*, loop=None) This class is almost compatible with concurrent.futures.Future. Differences: result() and exception() do not take a timeout argument and raise an exception when the future isn’t done yet. Callbacks registered with add_done_callback() are always called via the event loop’s call_soon_threadsafe(). This class is not compatible with the …

Read more

Best practices for turning jupyter notebooks into python scripts

Life saver: as you’re writing your notebooks, incrementally refactor your code into functions, writing some minimal assert tests and docstrings. After that, refactoring from notebook to script is natural. Not only that, but it makes your life easier when writing long notebooks, even if you have no plans to turn them into anything else. Basic …

Read more

Why is string’s startswith slower than in?

As already mentioned in the comments, if you use s.__contains__(“XYZ”) you get a result that is more similar to s.startswith(“XYZ”) because it needs to take the same route: Member lookup on the string object, followed by a function call. This is usually somewhat expensive (not enough that you should worry about of course). On the …

Read more

How to write a download progress indicator in Python?

There’s a text progress bar library for python at http://pypi.python.org/pypi/progressbar/2.2 that you might find useful: This library provides a text mode progressbar. This is tipically used to display the progress of a long running operation, providing a visual clue that processing is underway. The ProgressBar class manages the progress, and the format of the line …

Read more