replace a string

Michael Lewandowski michael at lewandowski.tc
Fri Sep 7 04:34:14 EDT 2001


hi there.
i'm completely new to python and i am writing a tool that opens
several .html files and writes the whole sourcecode in the variable
'quelltext'. now it checks if all metatags are correct. if e.g. the
<META NAME="author" CONTENT=""> -tag is missing it should actually
only insert this tag after <head> and write it back to the file and
close it to open the next one.
here is what i tried:
	metaautorregex = re.compile('<\s*meta\s*name\s*=\s*"\s*author\s*"',
re.IGNORECASE)
	autortag = metaautorregex.search(quelltext)
	if autortag:
		print ("metaautor vorhanden")
	else:
		b     = re.compile('<\s*head\s*>', re.IGNORECASE)
		tempo = b.search(quelltext)
		if tempo:
			quelltext = b.sub('\n<meta name="author"
content="'+addressautor(quelltext)+'">\n'+tempo.group(),quelltext,1)
			return quelltext

but it somehow doesn't really work because it doesn't replace the
string.
i would be really glad if someone could help me with this...
thx folks....



More information about the Python-list mailing list