Printing from a text file quirk
7stud
bbxx789_05ss at yahoo.com
Thu Mar 22 23:53:29 EDT 2007
On Mar 22, 9:34 pm, AWasile... at gmail.com wrote:
> 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!
Where can I see that? From the python language documentation here:
http://docs.python.org/lib/lib.html
you can look up readline() and see:
----------
readline( [size])
Read one entire line from the file. A trailing newline character is
kept in the string
---------
There is a function called strip() that will strip off all leading and
trailing whitespace on a string, e.g. a newline.
More information about the Python-list
mailing list