binary file
Scott David Daniels
Scott.Daniels at Acm.Org
Mon Jun 20 16:28:43 EDT 2005
Kent Johnson wrote:
> Nader Emami wrote:
>> Kent Johnson wrote:
>>> Nader Emami wrote:
>>>> I have used the profile module to measure some thing as the next
>>>> command:
>>>> profile.run('command', 'file')
>>>> ...How can I read (or convert) the binary file to an ascii file?
>>> Use an instance of pstats.Stats to interpret the results:
>>> from pstats import Stats
>>> s = Stats('file')
>>> s.print_stats()
>> I got the same result as the execution of command. But I would like to
>> write to the an external 'ascii' file!
> Oh, I get it, pstats.Stats doesn't have a way to send the output to a
> file. That's surprising!
I may be missing something here, but:
import sys, pstats
s = pstats.Stats('file')
sys.stdout, old = open('somefile.txt', 'w'), sys.stdout
s.print_stats()
sys.stdout, old = old, sys.stdout
old.close()
Looks to solve your problem to me.
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list