0

the code looks like this - has many prints for debug purposes. I want to have some toggle 'button' , one liner that enables/disables those print statements. without commenting out/in.

#age
            if (row['age'] < 25.0):
                print()
                print('age < 25')
                score += -45.0
                print('score changed to : %d ' % score)

            elif (row['age'] >= 25.0) and (row['age'] < 29.0):
                print()
                print('25 < age < 29')
                score += -22.0
                print('score changed to : %d ' % score)

            elif (row['age'] >= 29.0) and (row['age'] < 35.0):
                print()
                print('29 < age < 35')
                score += 1.0
                print('score changed to : %d ' % score)

            elif (row['age'] >= 35.0):
                print()
                print('age > 35')
                score += 19.0
                print('score changed to : %d ' % score)

            #f27
            if (row['f27']== ''):                
                print()
                print('f27 missing found')
                score += -18.0
                print('score changed to : %d ' % score)
1
  • Go for python logging and disable/enable logging level to None Commented Jan 28, 2020 at 11:44

1 Answer 1

4

Hope code below will help you.

from __future__ import print_function
debug  = True
def print(*args, **kwargs):
     if(debug):
             return __builtin__.print(*args, **kwargs)

The above code will override the builtin print function. it prints if debug set to True otherwise it skips print.

Sign up to request clarification or add additional context in comments.

2 Comments

wow thx but how is it called? is there separate print function out theere or is it called overloading print function?
It is a separate print function calling system print function, so that you don't have to change your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.