Sie sind nicht angemeldet.
Lieber Besucher, herzlich willkommen bei: Aqua Computer Forum. Falls dies Ihr erster Besuch auf dieser Seite ist, lesen Sie sich bitte die Hilfe durch. Dort wird Ihnen die Bedienung dieser Seite näher erläutert. Darüber hinaus sollten Sie sich registrieren, um alle Funktionen dieser Seite nutzen zu können. Benutzen Sie das Registrierungsformular, um sich zu registrieren oder informieren Sie sich ausführlich über den Registrierungsvorgang. Falls Sie sich bereits zu einem früheren Zeitpunkt registriert haben, können Sie sich hier anmelden.
powerslide
unregistriert
|
|
Quellcode |
1 |
<para class="heading1">text>/para> |
|
|
Quellcode |
1 |
<para class="heading.">.*?</para> |
|
|
Quellcode |
1 2 3 4 |
expr = re.sub ('<para class.*?', '', zu_ersetzen)
expr = re.sub ('</para>', '', expr)
code = "<p><b>%(expr)s</b></p>" % vars()
text = re.sub (zu_ersetzen, code, text)
|
|
|
Quellcode |
1 |
<para class="heading."> |
|
|
Quellcode |
1 2 |
for line in open('datei.txt'):
print line
|
|
|
Quellcode |
1 2 3 4 |
f = open('datei.txt')
for line in f:
print line
f.close()
|
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#!/usr/bin/env python
import re
infile = 'datei1.txt'
outfile = 'datei1a.txt'
out = open(outfile, 'w')
for line in open(infile):
tmp1 = re.sub('<para class=".+">', '<p><b>', line)
tmp2 = re.sub('</para>', '</b></p>', line)
out.write(line)
out.close()
|
powerslide
unregistriert
:-X powerslide
unregistriert
|
|
Quellcode |
1 2 |
re.sub('<para>(.+?)</para>', r'<p>\1</p>', line)
re.sub('<para class="heading(\d)">(.+?)</para>', r'<h\1>\2</h\1>', line)
|
powerslide
unregistriert
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# -*- coding: iso-8859-15 -*-
#!/usr/bin/env python
def convert():
import os
import string
import re
pfad = input("Suchpfad > ")
def filter1(infile, outfile):
out = open(outfile, 'w')
for line in open(infile):
re.sub('<para>(.+?)</para>', r'<p>\1</p>', line)
re.sub('<para class="heading.(\d)">(.+?)</para>', r'<p><b>\2</b></p>', line)
out.write(line)
out.close()
def findfiles(path, extension, depth=0):
for item in os.listdir(path):
itemWithPath = os.path.join(path, item)
if item.endswith(extension):
print 'Datei '+ item +' wird eingelesen' # file name only
datei = itemWithPath
newdat = path + 'new_' + item
print 'filter1 initialisiert'
filter1(datei, newdat)
print 'filter1 beendet
if os.path.isdir(itemWithPath):
findfiles(itemWithPath, extension, depth + 1)
findfiles(pfad, '.xml')
print 'Konvertierung abgeschlossen'
|
powerslide
unregistriert
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
def filter1(infile, outfile):
out = open(outfile, 'w')
for line in open(infile):
while 1:
ort = re.search ('<para class="heading.">.*?</para>', line)
if ort == None:
break
zu_ersetzen = ort.group()
print zu_ersetzen
expr = re.sub ('<para class.*?', '', zu_ersetzen)
expr = re.sub ('</para>', '', expr)
code = "<p><b>%(expr)s</b></p>" % vars()
print code
line = re.sub (zu_ersetzen, code, line)
out.write(line)
out.close()
|
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Traceback (most recent call last):
File "<pyshell#9>", line 1, in -toplevel-
convert()
File "H:\My Projects\python\filereader_v13.py", line 27, in convert
findfiles(pfad, '.xml')
File "H:\My Projects\python\filereader_v13.py", line 22, in findfiles
filter1(datei, newdat)
File "H:\My Projects\python\filter.py", line 44, in filter1
line = re.sub (zu_ersetzen, code, line)
File "C:\Python24\lib\sre.py", line 142, in sub
return _compile(pattern, 0).sub(repl, string, count)
File "C:\Python24\lib\sre.py", line 227, in _compile
raise error, v # invalid expression
error: unbalanced parenthesis
|
powerslide
unregistriert
-