Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conditional evaluation of source file in python

Tags:

python

Say I have a file that's only used in pre-production code

I want to ensure it gets not run in production code- any calls out to it have to fail.

This snippet at the top of the file doesn't work - it breaks the Python grammar, which specifies that return must take place in a function.

if not __debug__:
   return None

What is the best solution here - the one that doesn't involve making a gigantic else, that is. :-)

like image 341
Paul Nathan Avatar asked Jun 12 '26 14:06

Paul Nathan


1 Answers

if not __debug__:
    raise RuntimeError('This module must not be run in production code.')
like image 173
dappawit Avatar answered Jun 15 '26 03:06

dappawit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!