top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Implementing #define macros similar to C on python

+1 vote
184 views

I want to introduce the debug print something like this but in Python code.

#ifdef DEBUG_ENABLE
DEBUG_PRINT print
#else
DEBUG_PRINT

Is it possible to implement something similar in python?

posted Nov 15, 2013 by Salil Agrawal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

There are usually other ways to do things. For instance, you can define a function to either do something or do nothing:

if debug_mode:
 debug_print = print
else:
 debug_print = lambda: None

debug_print("This won't be shown unless we're in debug mode!")
answer Nov 15, 2013 by Luv Kumar
Similar Questions
+1 vote

Is any one aware of free ipython debugger tool. How good is this tool for a beginner to use like, placing breakpoints,checking variables ,call stack (function flow) etc.

I don't like to use python PDB. I have heard about wingware, pycharm which are licensed versions. Used wingware trail version and felt pretty good tool for beginners.

Please let know your views on ipython. Let me know about any python free debugger tools

+1 vote

I am trying to implement a multivibrator function with python. This is how it works;

  • An trigger event happens
  • Upon receiving the event, a variable goes high for 5secs, then go low.
  • If the event happens again before the 5secs expire, the high duration will be extended by another 5 secs. This works like a retriggerable multivibrator for those who are into electronics.

Is there some sample code for this problem or can someone point me to using the right library for this feature?

+1 vote

I found that most released apps(including system apps) can be debugged on the emulator by the way following:
1. install the app on the emulator, and launch it
2. run adb shell ps to get the pid of the app
3. run adb jdwp, if you find the pid in the output, then you can attach to the app by running
adb forward tcp:1234 jdwp:$pid_you_find and jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=1234
4. you can use commands such as "classes" to see the classes of the app, even "stop" to set breakpoint and "eval" to run many functions and see the members of the objects.
I have 2 questions:
1. Why these tricks fail on the phones? What's the difference between the rom of emulator and phones?
2. How to avoid my app being debugged through such way?

...