Is there a way to hide functions and such when they happen? Example:

print func(x, y)

from showing up when you run it?

I want it still printing, just not visible. I want it to print.

Edited by KrazyKitsune: n/a

8 Years
Discussion Span
Last Post by griswolf

I am confused.

  • From whom are you hiding the functions (and such)?
  • What do you mean by "when they happen"?
  • Can you give a longer example showing what you (don't) want to happen?

Edited by griswolf: n/a


Err.... so my program needs to print in order to test whether a function is properly working. But that test print is over 75 lines, and so I'd like to hide it from the user who uses it.


You can consider printing the output to file, or implement a debug switch so that it only print when certain option is passed in.


Some of my programs implement this function

def dribble(*args):
  if _debugging:

and use it liberally to help me understand the flow of the program. Most of those programs set _debugging at the top of the file, and I edit the file to turn it on or off (usually once to turn it off, after I'm done debugging). A few, however, have a command line switch -v == --verbose that sets it during program startup.

As cghtkh points out, you can also print to a file.

Better, probably, to use a logger to do whatever you need (it can write files and also/instead print to the screen on either sys.stdout or sys.stderr ). Python comes with a quite reasonable one, though you do have to play with it a bit at first if you haven't ever used one before. http://docs.python.org/library/logging.html Loggers give you quite a bit of control over logging output both while writing code: You get to set the severity level that triggers logging; and while running: You get to set the severity cut off level for this run for this logger. These cutoff levels can be set individually for each output hook, so for instance, you can set the severity level for console output to FATAL the severity level for the 'time tick logger' to INFO and the severity level for the development logger to DEBUG during development and NOTSET when running in the real world. In your code, some logging statements would be errors, some info, some debug, etc.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.