0

I have a condition that can be either True or False and depending on this condition I want to run a block of code inside a with statement or not, something like this:

if use_with:
    with bla_bla_bla:
        # Block of code
else:
    # Block of code

This does work, but it is a horrible code duplication prompt to problems in the future. What is the way of doing this?

user171780
  • 1,041
  • 8
  • 19

0 Answers0