Script for replacing digits
<p>I have a file that has content as below</p>

<pre><code>a      b     c    123.67989

aa   bb  cc   56789.38475

b    c   a    56789.3456

bb   cc  aa   0.12409124

c    a   b    0.0123123
</code></pre>

<p>I am trying to remove digits after the <code>.</code> in the each line. Is there is a way to do this using regular expressions in Python?
Code I wrote
f1 = open('filename.txt','r')</p>

<p>for line in f1:</p>

<pre><code>    words = line.split()
    print(words[3])
</code></pre>

<p>I am trying retrieve last row information and I keep getting error list indices out of range</p>

<p>No regex here, either, but:</p>

<pre><code>with open( "C:/TestFile.txt", 'r' ) as file:
   lines = file.readlines()

out_lines = []

out_file = open( "C:/TestFile2.txt", "w" )

for i in range( len( lines ) ):
   out_lines.append( lines[ i ].split( "." )[0] )

for line in out_lines:
   out_file.write( "%s\n" % line )
</code></pre>

<p>To access the numbers after the decimal, just access the second part of the split:</p>

<p>Python supports offset notation on strings, and you can access the second part of the split.</p>

<pre><code>for i in range( len( lines ) ):
   parts = lines[ i ].split( "." )
   out_lines.append( parts[0] )
   first_decimal = parts[1][0]
</code></pre>

<p>Or, if your goal is to round the values in the 4th column, something like this may be what you want:</p>

<pre><code>for i in range( len( lines ) ):
   parts = lines[i].split()

   if len( parts ) == 0:
      out_lines.append( "" )
      continue

   out_lines.append( parts[0].ljust( 5 ) + parts[1].ljust( 4 ) + parts[2].ljust( 5 ) + format( float( parts[3] ), '.1f' ) )
</code></pre>

python python-3.x