[Tutor] modified readline()???

Hugo González Monteverde hugonz-lists at h-lab.net
Tue Oct 19 07:51:51 CEST 2004


Hi all,

I'm invoking cdrecord from my python program, and I want to parse its 
progress so as  to paint a progress bar.

Now, I'd be doing:

filep = popen ("/mypath/cdrecord yabba yabba yabba")

then read from filep in a loop

If cdrecord sent the percentages in canonical form (ie, with \n between 
the lines) I could just do

while True:
	can_line = filep.readline()
	#here I'd look for the XX% string in the output, regexp or something
	if percentage == "100%":
		break
	
But the program just puts some kind of terminal control between status 
lines. Can I redefine the "CR" in readline() as to read up to that 
character??? I cannot simply use read() and block with some buffer size 
since that does not guarante I'm getting the whole "50%" string so that 
I can parse it.... I could be getting just 5 in one pass, and then 0% 
in the next....

Thanks all for your kind insight.... =)

Hugo


More information about the Tutor mailing list