Help with code = Extract numerical value to variable

Dave Angel davea at ieee.org
Fri Oct 23 07:16:28 EDT 2009


Steve wrote:
> Sorry I'm not being clear
>
> ****Input******
> sold: 16
> sold: 20
> sold: 2
> sold: 0
> sold: <storefront>
> 7
> 0
> <storefront>
> sold
> null
>
> ****Output****
> 16
> 20
> 2
> 0
> 0
> 7
> 0
> 0
> 0
> 0
>
>
>   
Since you're looking for only digits, simply make a string containing 
all characters that aren't digits.

Now, loop through the file and use str.translate() to delete all the 
non-digits from each line, using the above table.

Check if the result is "", and if so, substitute "0".  Done.

DaveA




More information about the Python-list mailing list