conditional

Conditionally enter a context manager
Download

conditional Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Stefan H. Holek
  • Publisher web site:
  • http://plone.org/products/cmftestcase

conditional Tags


conditional Description

conditional is a Python module that enters a contextmanager only if condition is true.OverviewThe conditional context manager comes handy when you always want to execute a with-block but only conditionally want to apply its context manager.If you find yourself writing code like this:if CONDITION: with CONTEXTMANAGER(): BODY()else: BODY()Consider replacing it with:with conditional(CONDITION, CONTEXTMANAGER()): BODY()ExamplesSay we want to ignore signals when a pager application is in the foreground, but not otherwise:from conditional import conditionalwith conditional(has_pager(cmd), ignoresignals()): os.system(cmd)Product's homepage


conditional Related Software