The #ifdef moon from Python?

Asked 2 years ago, Updated 2 years ago, 16 views

From C

#define TEST_MODE1
#define TEST_MODE2


#ifdef TEST_MODE1
Code executed only in test mode 1
#endif

#ifdef TEST_MODE2
Code executed only in Test Mode 2
#endif


#ifdef TEST_MODE1
#ifdef TEST_MODE2

Code executed only in test mode 1 and 2
#endif
#endif

I use it a lot.

What are the methods in python-pycharm environment?

It's not just that you can't see it and don't just log it, but I want to treat it as if it's missing when the code interprets it.

https://stackoverflow.com/questions/560040/conditional-compilation-in-python I want to write something like #ifdef that I can write more intuitively than this.

python

2022-09-22 11:13

1 Answers

https://stackoverflow.com/a/2987538/4439606

If you look at the answer here, there seems to be a pypreprocessor. Using this library

from pypreprocessor import pypreprocessor

pypreprocessor.parse()

#define debug

#ifdef debug
print('The source is in debug mode')
#else
print('The source is not in debug mode')
#endif

I think that's possible. I don't use Python often, so I don't know about the package, but I heard that it can be installed with PYPI. I think it would be good to go into the link and read it.


2022-09-22 11:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.