By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,379 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

binary file

P: n/a
L.S.,

I have used the profile module to measure some thing as the next command:

profile.run('command', 'file')

But this make a binary file! How can I write the result of 'profile' in
a ascii file? Others how can I read (or convert) the binary file to am
ascii file?

Regards,
Nader
Jul 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Nader Emami wrote:
L.S.,

I have used the profile module to measure some thing as the next command:

profile.run('command', 'file')

But this make a binary file! How can I write the result of 'profile' in
a ascii file? Others how can I read (or convert) the binary file to am
ascii file?


Use an instance of pstats.Stats to interpret the results:

from pstats import Stats
s = Stats('file')
s.print_stats()

etc.
http://docs.python.org/lib/profile-stats.html

Kent
Jul 19 '05 #2

P: n/a
Kent Johnson wrote:
Nader Emami wrote:
L.S.,

I have used the profile module to measure some thing as the next command:

profile.run('command', 'file')

But this make a binary file! How can I write the result of 'profile'
in a ascii file? Others how can I read (or convert) the binary file to
am ascii file?

Use an instance of pstats.Stats to interpret the results:

from pstats import Stats
s = Stats('file')
s.print_stats()

etc.
http://docs.python.org/lib/profile-stats.html

Kent

I got the same result as the execution of command. But I would like to
write to the an external 'ascii' file!

Thanks!

Jul 19 '05 #3

P: n/a
Nader Emami wrote:
Kent Johnson wrote:
Nader Emami wrote:
L.S.,

I have used the profile module to measure some thing as the next
command:

profile.run('command', 'file')

But this make a binary file! How can I write the result of 'profile'
in a ascii file? Others how can I read (or convert) the binary file
to am ascii file?


Use an instance of pstats.Stats to interpret the results:

from pstats import Stats
s = Stats('file')
s.print_stats()

etc.
http://docs.python.org/lib/profile-stats.html

Kent


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!

One option would be to write a program that outputs what you want, then redirect the output in the shell. Alternatively take a look a the source for print_stats() and write your own that outputs to a file.

Kent
Jul 19 '05 #4

P: n/a
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
Sc***********@Acm.Org
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.