"""
file_nom =3D '/home/remi/droit_tice/faq_gest.tex'
file_lignes =3D [x for x in open(file_nom,'r').readlines() if x[0]<>'%']
## ignore toutes les lignes commen=E7ant par au moins un %
## en plus, il n'y a aucun besoin de << FICHIER.close() >>
file_string =3D ''.join(file_lignes)
"""
def remplacer(t,c,f):
while True:
try:
i =3D t.index(c)
j =3D i + t[i:].index('{')
k =3D j + t[j:].index('}')
t =3D t.replace(t[i:k+1],f(t[j+1:k]))
except: break
return t
c1 =3D '\\url'
f1 =3D lambda x: '\n<a href =3D "' + x + '">' + x + '</a>'
texte1 =3D '''
tralalala nil nisi divinum stabile est
\\url{adresse_web_0}
the naming of cats is a difficult matter
\\url{adresse_web_1}
i shall wear the bottoms of my trousers rolled
\\url{adresse_web_2}
headpiece filled with straw, alas
'''
texte2 =3D '''
tralalala nil nisi divinum stabile est
\\textit{titre_0}
the naming of cats is a difficult matter
\\textit{titre_1}
i shall wear the bottoms of my trousers rolled
\\textit{titre_2}
headpiece filled with straw, alas
'''
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Sean McIlroy
# -*- coding: Latin-1 -*-
from cStringIO import StringIO import re
def xReplace(t,a,b): if not a: return t return xReplace(t.replace(a[0],b[0]),a[1:],b[1:])
def remplacer(t,c,f): while True: try: i = t.index(c) j = i + t[i:].index('{') k = j + t[j:].index('}') t = t.replace(t[i:k+1],f(t[j+1:k])) except: break return t
def pardeux(iterable, n=2): it = iter(iterable) next = it.next while True: yield next(), next()
i = j = 1 for titre, contenu in pardeux(contents_list[1:]): contenus_sections = re.split(re.compile(r'subsection{(.*)}'),contenu) fout.write('<section id="%s" name="%s" description="%s">n' % (str(i),titre,str(normalize_whitespace(contenus_sections[0])) )) for titre_ssect, contenu_sect in pardeux(contenus_sections[1:]): fout.write('<sousSection id="%s" thema="%s">' % (str(j),normalize_whitespace(titre_ssect))) fout.write('<![CDATA[%s]]>' % normalize_whitespace(contenu_sect)) fout.write('</sousSection>n') j=j+1 fout.write('</section>n') i=i+1 fout.write('</document>')
open('out.xml','w').write(fout.getvalue())
# -*- coding: Latin-1 -*-
from cStringIO import StringIO
import re
def xReplace(t,a,b):
if not a: return t
return xReplace(t.replace(a[0],b[0]),a[1:],b[1:])
def remplacer(t,c,f):
while True:
try:
i = t.index(c)
j = i + t[i:].index('{')
k = j + t[j:].index('}')
t = t.replace(t[i:k+1],f(t[j+1:k]))
except: break
return t
def pardeux(iterable, n=2):
it = iter(iterable)
next = it.next
while True:
yield next(), next()
def xReplace(t,a,b): if not a: return t return xReplace(t.replace(a[0],b[0]),a[1:],b[1:])
def remplacer(t,c,f): while True: try: i = t.index(c) j = i + t[i:].index('{') k = j + t[j:].index('}') t = t.replace(t[i:k+1],f(t[j+1:k])) except: break return t
def pardeux(iterable, n=2): it = iter(iterable) next = it.next while True: yield next(), next()
Un joli "one-liner" ;-) Comme il y en a plusieurs. il manque plus qu'une écriture plus OO comme un autre intervenant l'a proposé. :-) @+ et merci ! Vive fclp ! Rémi
Un joli "one-liner" ;-) Comme il y en a plusieurs.
il manque plus qu'une écriture plus OO comme un autre intervenant l'a
proposé.
:-)
@+ et merci !
Vive fclp !
Rémi
Un joli "one-liner" ;-) Comme il y en a plusieurs. il manque plus qu'une écriture plus OO comme un autre intervenant l'a proposé. :-) @+ et merci ! Vive fclp ! Rémi