I need to update a text file whenever my IP address changes, and then run a few commands from the shell afterwards.
Create variable LASTKNOWN = \"212.171.13
fileinput module has very ugly API, I find beautiful module for this task - in_place, example for Python 3:
import in_place
with in_place.InPlace('data.txt') as file:
for line in file:
line = line.replace('test', 'testZ')
file.write(line)
main difference from fileinput:
for example - fileinput can line by line editing only, in_pace allow read whole file to memory (if it not big) and modify it.