python: find and replace numbers < 1 in text file

Posted by hjp on Stack Overflow See other posts from Stack Overflow or by hjp
Published on 2010-04-21T17:09:56Z Indexed on 2010/04/21 17:13 UTC
Read the original article Hit count: 174

Filed under:
|

I'm pretty new to Python programming and would appreciate some help to a problem I have...

Basically I have multiple text files which contain velocity values as such:

0.259515E+03 0.235095E+03 0.208262E+03 0.230223E+03 0.267333E+03 0.217889E+03 0.156233E+03 0.144876E+03 0.136187E+03 0.137865E+00

etc for many lines...

What I need to do is convert all the values in the text file that are less than 1 (e.g. 0.137865E+00 above) to an arbitrary value of 0.100000E+01. While it seems pretty simple to replace specific values with the 'replace()' method and a while loop, how do you do this if you want to replace a range?

thanks

© Stack Overflow or respective owner

Related posts about python

Related posts about search-and-replace