Replace a portion of a specific line
<p>I do in python an history file, so that a user puts an URL and after that the program writes the URL in a txt file and on the same link the time that the user enter the website.</p>

<p>So my txt is like below:</p>

<pre><code>- google.com 14:30
- yahoo.com 17:06
- apple.com 23:02
</code></pre>

<p>I want to create a function, so that the user put the url who wants to edit in parameter the time will be changed with the current time. The problem is that I do this function but when I see in the txt file I have something like this</p>

<pre><code>google.com current_time 14:30
</code></pre>

<p>So I want to know who to delete the <code>14:30</code> from the txt file inplace.
Thanks you !</p>

<p>This is my function :</p>

<pre><code>def Update(link):
    for line in fileinput.input("history.txt", inplace=True):
        localtime = time.asctime(time.localtime(time.time()))
        print line.rstrip().replace(link, link+ localtime)
</code></pre>

<p>You can use regular expressions.</p>

<pre><code>import re

def Update(link):
    for line in fileinput.input("history.txt", inplace=True):
        localtime = time.asctime(time.localtime(time.time()))
        print re.sub('\d{2}:\d{2}', localtime, line)
</code></pre>

python