I'm trying to parse xml file and convert all the unix timestamps in it to datetime...
<Sample>
<TimeStamp>1291052077</TimeStamp>
blah blah
blah blah
</Sample><Sample>
<TimeStamp>1291052077</TimeStamp>
blah blah
blah blah
</Sample>
</Content>
import fileinput
file = raw_input("Enter file: ")
file = open(file, "wb+")
for line in fileinput.FileInput(file,inplace=1):
if "TimeStamp" in line:
line=line.replace(<old>,<new>) // don't know how to get all instances of the time
pass
print(datetime.datetime.fromtimestamp(int("1284101485")).strftime('%Y-%m-%d %H:%M:%S'))
I've got some clues as above, but struggling to piece together things. Any thoughts?