You are not logged in.
Dear visitor, welcome to Aqua Computer Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.
powerslide
Unregistered
|
|
Source code |
1 |
<para class="heading1">text>/para> |
|
|
Source code |
1 |
<para class="heading.">.*?</para> |
|
|
Source code |
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)
|
|
|
Source code |
1 |
<para class="heading."> |
|
|
Source code |
1 2 |
for line in open('datei.txt'):
print line
|
|
|
Source code |
1 2 3 4 |
f = open('datei.txt')
for line in f:
print line
f.close()
|
|
|
Source code |
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
Unregistered
:-X powerslide
Unregistered
|
|
Source code |
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
Unregistered
|
|
Source code |
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
Unregistered
|
|
Source code |
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()
|
|
|
Source code |
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
Unregistered
-