Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8814659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:11:04+00:00 2026-06-14T04:11:04+00:00

In C we write code like #ifdef DEBUG printf(Some debug log… This could probably

  • 0

In C we write code like

#ifdef DEBUG
printf("Some debug log... This could probably be achieved by python logging.Logger");
/* Do some sanity check code */
assert someCondition
/* More complex sanitycheck */
while(list->next){
assert fooCheck(list)
}

#endif

Is there a way to do this in python?

Edit: I got my answer, and more 🙂
Paolo, Steven Rumbalski and J Sebastian gave me the information I was looking for. Thanks das for the detailed answer, although I’ll probably not use a preprocessor right now.

J Sebastian, whose comment got deleted because the answer in which he posted his comment, deleted his answer I think.
He said I could use the isEnabledFor() method in Logger to feed a conditional.

Thanks everyone for your inputs. This is my first question. I wish I could accept paolo, or j sebastian’s answers. But since those were offered as comments, I’ll accept das’ answer.

I will probably use either http://nestedinfiniteloops.wordpress.com/2012/01/15/if-debug-python-flavoured/ or Logger.isEnabledFor()

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:11:05+00:00Added an answer on June 14, 2026 at 4:11 am

    What you are looking for is a preprocessor for python. Generally you have three options:

    1. Write a selfmade script/program which replaces parts of your sourcecode based on certain templates before passing the result on to the interpreter (May be difficult)
    2. Use a special purpose python preprocessor like pppp – Poor’s Python Pre-Processor
    3. Use a general purpose preprocessor like GPP

    I recommend trying pppp first 😉

    The main advantage of a preprocessor compared to setting a DEBUG flag and running code if (DEBUG == True) is that conditional checks also cost CPU cycles, so it is better to remove code that does not need to be run (if the python interpreter doesn’t do that anyway), instead of skipping it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a code that could print something like this -xv -xvv
So I can write code like this: #ifdef [whatever] // do stuff that will
Is it possible to write code like this? public void DoSomeOperation().Log() { }.Log() Above
I saw some ppl write code like this: They use __ in the naming
When I write code in Python with exception handling I can write code like:
I was wondering how to better write code like this so that it leverages
I occasionally write code something like this: // file1.cpp #define DO_THIS 1 #if DO_THIS
<a href=details.php?phoneid=1><img src=phone01.jpg></a> When I write the code like this it's working fine. But
In code, if I write a code line like this: GClass<Double> x = new
I use to write code like this: void fun(char *buff, unsigned size) { std::strstream

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.