Linked Questions

-1 votes
1 answer
536 views

Say I have a python program composed of three lines. if __name__=“__main__”: foo( ) print “Hello” Here, foo( ) is a third-part function that outputs things to the standard output. E.g, foo( ) ...
zell's user avatar
  • 10.4k
0 votes
1 answer
282 views

I have a small selection of code: stream = pyaudio.PyAudio().open( format = pyaudio.PyAudio().get_format_from_width(1), channels = 1, rate = bitrate, output = True ) When I ...
d3pd's user avatar
  • 8,375
447 votes
15 answers
816k views

How do I redirect stdout to an arbitrary file in Python? When a long-running Python script (e.g, web application) is started from within the ssh session and backgounded, and the ssh session is closed,...
user avatar
85 votes
8 answers
95k views

Is there a way in Python to silence stdout without wrapping a function call like following? Original Broken Code: from sys import stdout from copy import copy save_stdout = copy(stdout) stdout = ...
Tim McJilton's user avatar
  • 7,444
50 votes
2 answers
25k views

I don't think this is possible, but I want to handle exceptions from argparse myself. For example: import argparse parser = argparse.ArgumentParser() parser.add_argument('--foo', help='foo help', ...
joedborg's user avatar
  • 18.5k
29 votes
6 answers
22k views

I am using Python's hotshot profiler: http://docs.python.org/2/library/hotshot.html It shows how to print the stats: stats.print_stats(20) But how do I get that into a file? I'm not sure how to get ...
user984003's user avatar
  • 29.9k
12 votes
3 answers
16k views

There're lots of print function (python 2.7) in my program. Is there any way I can add a few lines then all the output can be redirected to stderr? What I want is python codes but not linux pipeline. ...
waitingkuo's user avatar
  • 94.5k
5 votes
4 answers
20k views

Short version (if you can answer the short version it does the job for me, the rest is mainly for the benefit of other people with a similar task): In python in Windows, I want to create 2 file ...
user302099's user avatar
11 votes
2 answers
12k views

Is there any way in Pandas to capture the warning produced by setting error_bad_lines = False and warn_bad_lines = True? For instance the following script: import pandas as pd from StringIO import ...
eroma934's user avatar
  • 339
4 votes
3 answers
11k views

As you know, python smtplib has a debug level.When I set it a true param, it will print some send information. The problem is, I try to get the debug info to log into a file, but They just stay on my ...
soasme's user avatar
  • 392
1 vote
2 answers
8k views

I am trying to pipe the output of the following command to /dev/null so that it doesn't get printed for the user that is running the program. import os os.system("ping -c 1 192.168.unknown.host > /...
orezvani's user avatar
  • 3,815
10 votes
1 answer
2k views

i can silence and restore sys.stdout this way: import sys sys.stdout = None print('hello') # does not write to stdout sys.stdout = sys.__stdout__ print('hello') # writes to stdout i know i'd better ...
hiro protagonist's user avatar
4 votes
3 answers
2k views

Suppose we have the following dummy function: import sys def writeline(text, stream=sys.stdout): stream.write(text + '\n') with open('/path/to/file', 'w') as f: # writes to /path/to/file ...
farsil's user avatar
  • 1,055
5 votes
1 answer
3k views

I would like to capture error messages which are generated from a python module A. A is written in C++ and SWIG, and so I cannot capture Python's sys.stderr. >>> import A >>> A.func(...
Akira Okumura's user avatar
2 votes
2 answers
2k views

Is there any function do the same result like PHP ob_start(myCallbackFunction) and ob_end_flush() that allow me modify the layouts and views in Python frameworks (Django/others)? thanks! UPDATE <?...
user avatar

15 30 50 per page