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 224609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:19:58+00:00 2026-05-11T19:19:58+00:00

When debugging, I like to print out all the inputs and outputs of a

  • 0

When debugging, I like to print out all the inputs and outputs of a function (I know I need a better IDE, but humour me, this could be used for error reporting). So, I’d ideally like to have:

@debuggable
def myfunc(argA,argB,argC):
    return argB+1

and use a global variable to switch on or off debugging. No, you don’t like globals either, I guessed.

The best I can come up with is:

DEBUG = True

def debuggable(func):
    if DEBUG:
        def decorated(*args):
            print "Entering ",func.func_name
            print "    args ",args
            ret = func(*args)
            print ret
            return ret
        return decorated
    else:
        return func

@debuggable
def myfunc(this,that):
    return this+that

And running:

>>> myfunc(1,3)
Entering  myfunc
   args  (1, 3)
4

How can I improve that?

  • 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-05-11T19:19:58+00:00Added an answer on May 11, 2026 at 7:19 pm

    Use a debugger. Seriously. Decorating every function you want to keep track is a bad idea.

    Python has a debugger included, so you don’t need a good IDE.

    If you don’t want to use a debugger, you can use the trace function.

    import sys
    
    @sys.settrace
    def trace_debug(frame, event, arg):
        if event == 'call':
            print ("calling %r on line %d, vars: %r" % 
                    (frame.f_code.co_name, 
                     frame.f_lineno,
                     frame.f_locals))
            return trace_debug
        elif event == "return":
            print "returning", arg
    
    def fun1(a, b):
        return a + b
    
    print fun1(1, 2)
    

    That prints:

    calling 'fun1' on line 14, vars: {'a': 1, 'b': 2}
    returning 3
    3
    

    Even easier would be to use Winpdb:

    It is a platform independent graphical GPL Python debugger with support for remote debugging over a network, multiple threads, namespace modification, embedded debugging, encrypted communication and is up to 20 times faster than pdb.

    Features:

    • GPL license. Winpdb is Free Software.
    • Compatible with CPython 2.3 or later.
    • Compatible with wxPython 2.6 or later.
    • Platform independent, and tested on Ubuntu Gutsy and Windows XP.
    • User Interfaces: rpdb2 is console based, while winpdb requires wxPython 2.6 or later.

    Screenshot
    (source: winpdb.org)

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

Sidebar

Related Questions

I find myself adding debugging print statements quite often -- stuff like this: print(a_variable_name:
Quite simply I'd like to print out all variables that are in scope in
I'd like to know how debugging is achieved in a lazy functional language. Can
Is there a decent IDE-like tool for writing and debugging PL/pgSQL functions, e.g. for
I am debugging on a large code base and I’d like to know what
This seems like it should be an easy fix, but after searching for hours
I have a function like this try { using(var sConnection = new SqlConnection(ConnectionString)) using(var
I'd like to use all the power of Xcode for generic C/C++ projects but
This is an extremely strange situation, but I just cannot point out what I'm
I have this gdb macro, which is used to print meaningful stacktraces when debugging

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.