Editing a SPECIFIC word in a file in python, every 20 mins
<p>I want to change the value of omega in the file below at a specific interval, say every 30 minutes. This file is used by another program at runtime. I would like to ramp the RPM value (the last entry on the line) from 0-10 slowly. Essentially, the value "5" in the file below needs to change from 0-10 in increments of 1 every 30 minutes.</p>

<pre><code>rotor
{
    // Fixed patches (by default they 'move' with the MRF zone)
    nonRotatingPatches (); //if something blows up ..fill the non rotating patches between "(baffles, pressureOutlet etc)"

    origin    origin [0 1 0 0 0 0 0]  (0 0 0);
    axis      axis   [0 0 0 0 0 0 0]  (0 0 1);
    omega    omega [0 0 -1 0 0 0 0] 5;
}
</code></pre>

<p>I have tried the following code (I don't know how to do the every 30 minutes part), but the data written by the<code>file.writelines(data)</code> method doesn't seem to incorporate the change I make to the value.</p>

<pre><code>import os
import sys
import fileinput

with open('MRFzones', 'r') as file:
    data = file.readlines()

# The line omega is line 27 in the file.
line = data[26]
word = line.split()

# &gt;&gt;&gt; data[26].split()
# ['omega', 'omega', '[0', '0', '-1', '0', '0', '0', '0]', '5;'] 
# The part i want to change is the 10th word.
word[9] = '10;'

# Write everything back.
with open('MRFzones', 'w') as file:
    file.writelines(data)
</code></pre>

<p>This is not working - the 5 is not being changed into 10 in the updated file. Can someone help me implement this? I might not even have the right idea, so we could start the code from scratch if necessary.</p>

<p>Thanks, 
Suresh</p>
