I have a html document saved as a text file that I'm trying to load. Its just the header section so my object is to read all the lines till I hit the <title> tag, break, then read the rest. I have kinda achieved what I wanted, but I'm getting a new line where I stopped. It will become clear once you see the code. So my question is how do I fix it, or is their an easier way?
Python code: self.headertxt = open("pages/header.html","r") *** Irrelevant code omitted *** headerp1 = "" for i in range(5): headerp1 += self.headertxt.readline() headerp2 = self.headertxt.readline(7) headerp3 = self.headertxt.readline() headerp4 = self.headertxt.read() return headerp1 + headerp2 + headerp3 + pagetitle + headerp4 Here is the textfile im reading: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta name="Generator" content="EditPlus" /> <meta name="Author" content="Adam W." /> <meta name="Description" content="Blah Blah Blah" /> </head>""" and here is the output: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> this is a new title </title> <meta name="Generator" content="EditPlus" /> <meta name="Author" content="Adam W." /> <meta name="Description" content="Blah Blah Blah" /> </head>""" As you can see what I was trying to acheive was <title>the title</ title> all on the same line. Help! -- http://mail.python.org/mailman/listinfo/python-list