포스트

python debugPrint 커스텀 프린트

개발을 할 때면 특정 용도에 따라 print문을 실행하거나 하지 않는 스위치를 두는 것이 유용할 때가 많습니다.

python에도 그런 함수를 만들어서 사용할 수 있습니다.

1
2
3
4
5
6
7
8
9
10
11
12
DEBUG = True

def debugPrint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)

# Example usage
debugPrint("This is a debug message", "with multiple arguments", end=".\n")

msg = "Hello this is example sentence"
debugPrint(msg)

이런 식으로 Boolean DEBUG 변수를 스위치로 두고, debugPrint 함수를 print 함수 대신에 사용하시면 됩니다.

sticker

감사합니다.

이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.