Python text to xml converting solutions
Hi guys i have write some code in python and its look like :
! /usr/bin/env python
import re
output = open('epg.xml','w') n = 0 print >> output, ''+'\t' print >>
output, ''
with open('epg_slo_utf_xml.txt','r') as txt: for line in txt: if
re.search('Program', line) !=None:
n =n + 1 e =''+line+''
if re.search('Start', line) !=None:
n = n + 1
f ='<start>'+line+'</start>'
if re.search('duration', line) !=None:
n = n + 1
g ='<duration>'+line+'<duration>'
wo = e + f
print >> output, wo
print >> output , '
But when I wanna add code for discovering Duration from my text file, like
this:
if re.search('duration', line) !=None: n = n + 1 g =''+line+''
And when I run script i get this error message :
Traceback (most recent call last):
File "./epg_transform.py", line 25, in <module>
wo = e + f + g
NameError: name 'g' is not defined
My text file look's like this :
Program 5
Start 2013-09-12 05:30:00
Duration 06:15:00
Title INFOCANALE
Program 6
Start 2013-09-12 06:40:00
Duration 00:50:00
Title Vihar
Program 9
Start 2013-09-12 06:45:00
Duration 00:29:00
Title TV prodaja
Program 7
Program 6
Program 13
Start 2013-09-12 06:20:00
Duration 00:50:00
Title Kursadije
I think that problem is when re.search find Program but without other
element's in text file or maybe Program with multiplay start, duration,
title like:
Program 7
Start 2013-09-16 00:10:00 Duration 02:00:00 Title Love TV
Start 2013-09-16 02:10:00 Duration 01:50:00 Title Noèna ptica
Thx, for reading and can you help me with this problem?
No comments:
Post a Comment