[Tutor] Parsing os.popen(command) output

Orri Ganel singingxduck at gmail.com
Sun Sep 11 21:49:10 CEST 2005


Bill Burns wrote:

>Kent,
>
>Thank you for the reply! I knew there had to be a different way to do
>it, I didn't like the three lists in there either :-)
>
>One thing:
>I had to change the line
>
>wRes = float(data[1][1:])
>
>it was returning '00,' (zero, zero, comma) instead of '400', so I
>changed it to this:
>
>wRes = float(data[1][:3])
>
>but then I thought, what if I get a tif with a resolution that is <>
>than 3 digits?
>
>So I opted for this
>
>wRes = float(data[1].strip(','))
>
>which seems to work fine.
>
>Thanks again!!
>
>Bill
>
>
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>  
>
You could just do

wRes = float(data[1][:-1]) (up to the last digit, which would be the comma)

-- 
Email: singingxduck AT gmail DOT com
AIM: singingxduck
Programming Python for the fun of it.



More information about the Tutor mailing list