diff --git a/Lib/pstats.py b/Lib/pstats.py index c3a88284ca7..4e94b0ce0ee 100644 --- a/Lib/pstats.py +++ b/Lib/pstats.py @@ -548,8 +548,10 @@ def __init__(self, profile=None): self.prompt = "% " if profile is not None: self.stats = Stats(profile) + self.stream = self.stats.stream else: self.stats = None + self.stream = sys.stdout def generic(self, fn, line): args = line.split() @@ -667,14 +669,15 @@ def postcmd(self, stop, line): return None import sys - print >> self.stream, "Welcome to the profile statistics browser." if len(sys.argv) > 1: initprofile = sys.argv[1] else: initprofile = None try: - ProfileBrowser(initprofile).cmdloop() - print >> self.stream, "Goodbye." + browser = ProfileBrowser(initprofile) + print >> browser.stream, "Welcome to the profile statistics browser." + browser.cmdloop() + print >> browser.stream, "Goodbye." except KeyboardInterrupt: pass