<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:v =
"urn:schemas-microsoft-com:vml" xmlns:o =
"urn:schemas-microsoft-com:office:office" xmlns:w =
"urn:schemas-microsoft-com:office:word" xmlns:m =
"http://schemas.microsoft.com/office/2004/12/omml"><HEAD><TITLE>Message</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.5730.13" name=GENERATOR>
<STYLE>@font-face {
        font-family: Calibri;
}
@page WordSection1 {size: 612.0pt 792.0pt; margin: 3.0cm 2.0cm 3.0cm 2.0cm; }
P.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Calibri","sans-serif"; mso-fareast-language: EN-US
}
LI.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Calibri","sans-serif"; mso-fareast-language: EN-US
}
DIV.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Calibri","sans-serif"; mso-fareast-language: EN-US
}
A:link {
        COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlink {
        COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
A:visited {
        COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlinkFollowed {
        COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.EmailStyle17 {
        COLOR: windowtext; FONT-FAMILY: "Calibri","sans-serif"; mso-style-type: personal-compose
}
.MsoChpDefault {
        FONT-FAMILY: "Calibri","sans-serif"; mso-fareast-language: EN-US; mso-style-type: export-only
}
DIV.WordSection1 {
        page: WordSection1
}
</STYLE>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></HEAD>
<BODY lang=DA vLink=purple link=blue>
<DIV><FONT face=Tahoma><FONT size=2><SPAN class=701514815-12012011><FONT
face=Arial color=#0000ff>You should have a comma after the "#" in the
highlighted print statement, that should repress the new line (I'm guessing
that's the line you're talking about)</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Tahoma><FONT size=2><SPAN
class=701514815-12012011></SPAN></FONT></FONT> </DIV>
<DIV><FONT face=Tahoma><FONT size=2><SPAN class=701514815-12012011><FONT
face=Arial color=#0000ff>print >>
f,t,"#",</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Tahoma><FONT size=2><SPAN
class=701514815-12012011> </SPAN></FONT></FONT></DIV>
<DIV><FONT face=Tahoma><FONT size=2><SPAN class=701514815-12012011>
<DIV align=left>
<DIV align=left><FONT face=Verdana size=2>Jason</FONT></DIV>
<DIV align=left><FONT face=Verdana size=2></FONT> </DIV>
<DIV align=left><FONT face=Verdana size=2></FONT> </DIV>
<DIV align=left><FONT face=Verdana size=2></FONT> </DIV>
<DIV align=left><FONT face=Verdana color=#ffffff
size=1>..·><((((º></FONT></DIV></DIV></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Tahoma><FONT size=2><SPAN
class=701514815-12012011> </SPAN>-----Original Message-----<BR><B>From:</B>
tutor-bounces+jasons=adventureaquarium.com@python.org
[mailto:tutor-bounces+jasons=adventureaquarium.com@python.org] <B>On Behalf Of
</B>Tommy Kaas<BR><B>Sent:</B> Wednesday, January 12, 2011 10:40
AM<BR><B>To:</B> tutor@python.org<BR><B>Subject:</B> [Tutor] how avoid writing a
newline?<BR><BR></DIV></FONT></FONT>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=WordSection1>
<P class=MsoNormal><SPAN lang=EN-US>I’m using Activepython 2.6.6 on
PC/Win7<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>I have made a small scraper script as an
exercise for myself. <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>It scrapes the name and some details of
the first 25 billionaires on the Forbes list.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>It works and write the result in a text
file, with the columns separated by “#”<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>It takes the name from the link (t =
i.string) – open the link and scrape details from the next
page.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>But I can’t find a way to write the name
(the variable t) one and only one time in the beginning of the
line.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>As t is written now I get it in the
beginning of the line but I also get a newline. <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>Can I avoid that in a simple
way?<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>Thanks in advance for any
help<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>Tommy<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>from BeautifulSoup import
BeautifulSoup<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>from mechanize import
Browser<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>f = open("forbes.txt",
"w")<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>br = Browser()<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>url =
"http://www.forbes.com/lists/2010/10/billionaires-2010_The-Worlds-Billionaires_Rank.html"<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>page = br.open(url)<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>html = page.read()<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>soup =
BeautifulSoup(html)<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>table =
soup.find("table")<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>l =
table.findAll('a')<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>for i in l[5:]:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US> t =
i.string<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US> print t #to the
monitor<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US> <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
lang=EN-US> br.follow_link(text_regex=r"(.*?)"+t+"(.*?)")<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US> tekst =
br.response().read()<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US> soup =
BeautifulSoup(tekst)<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US> table1 =
soup.find('table', id='billTable')<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US> rows =
table1.findAll('tr')<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US> <SPAN
style="BACKGROUND: yellow; mso-highlight: yellow">print >> f,
t,"#"</SPAN> <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US> for tr in
rows:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>
tds = tr.findAll(text=True)<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>
print >> f, tds[1].string,"#",tds[2].string,"#", <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US> print >> f,
'\r\n'<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US>f.close()<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN
lang=EN-US><o:p> </o:p></SPAN><o:p> </o:p></P></DIV></BLOCKQUOTE></BODY></HTML>