Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.04; 'modified': 0.05; 'modify': 0.05; 'skip:$ 30': 0.07; 'subject:How': 0.09; '"%s"': 0.09; 'answering': 0.09; 'lines:': 0.09; 'script,': 0.09; 'subject:script': 0.09; 'def': 0.10; 'kurt': 0.11; 'programmer': 0.11; 'advance.': 0.15; 'modification': 0.15; "'';": 0.16; "(i'm": 0.16; 'columns': 0.16; 'item)': 0.16; 'received:98.138.89.199': 0.16; 'rewriting': 0.16; 'script?': 0.16; 'test.': 0.17; '>>>': 0.18; 'to:name:python-list@python.org': 0.20; '>>>': 0.22; 'skip:$ 20': 0.22; '>': 0.23; 'to:2**1': 0.23; "i've": 0.23; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'skip:" 20': 0.26; 'question': 0.27; 'to?': 0.27; 'lines': 0.28; 'url:mailman': 0.29; 'convert': 0.29; 'skip:& 10': 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'url:python': 0.32; 'could': 0.32; 'skip:_ 30': 0.32; 'print': 0.32; 'url:listinfo': 0.32; 'to:addr:python-list': 0.33; 'skip:& 20': 0.33; 'text': 0.34; 'reply-to:addr:yahoo.com': 0.34; 'table': 0.35; 'subject:?': 0.35; 'subject:': 0.36; 'but': 0.36; 'url:org': 0.36; 'apple': 0.36; 'email addr:python.org': 0.36; 'thank': 0.36; 'item': 0.37; 'sent:': 0.37; 'subject:: ': 0.38; 'green': 0.38; 'from:': 0.38; 'skip:l 20': 0.38; 'several': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'skip:" 10': 0.40; 'url:mail': 0.40; 'your': 0.60; 'places': 0.61; 'first': 0.61; 'email name:python-list': 0.62; 'different': 0.63; 'show': 0.63; 'price': 0.66; 'url:content': 0.66; 'header:Reply-To:1': 0.68; 'received:41': 0.73; 'subject:this': 0.84; '2013': 0.84 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 699320.80976.bm@omp1057.mail.ne1.yahoo.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1357480908; bh=hj7B2ZV1QopygpX2q0o1Fa9Ck7OEBi+n7/v56eXmVyQ=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=XxiiEPvpimkjpjH1C0z0g5lj6wWh0OnQgtbJRkNymHSqC2K0PtxKubYCtSazGboKoTxIA/saX3iVMf5m5RHpMjLGxkCrZyNRvfccU6WiocRWheSWkDwFrmM/Nj/ZscgThxBt7M1QGNVgjNuNJDERRAlHUfmC3XFdmOhLN5EoQ0c= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=T3SZI2bHkb6MiKy/ZTjvG93rnQQk90qJIJtxLyNyE4JpOhjV615uuC0/XFXcqiMukZN5OinrN3s0twctmJy8Ljdth9it27hSQuGe9pCHvzeOHbV9Ral4RrAo8/xiGcE47sxP/jvJP8Lju5UQm9yxpZnOGQMmfIDmALqu0bLoa1I=; X-YMail-OSG: By.oYJcVM1nZmS.wjMuQfmRRy3wBNSUvxrFsywJ6jGrGZ7t KKytRCUeQQN9l4Y01C7JaL_SqMPjUfVcMLR4XsveP7uPAgdD_Su4I4OnXZDA u3Uux6WJJBIhPMd3mRUyHgVQss7XIcNxZ530XzVdhJDA7eZCCOytBHnrS9kE o.Fwi296QCXFw_Ts6ukJKD46ROVOTQfiP0K2heIYRKJSOSkjYTb8RE48wtuO Po_ylfmyMmaVpZHWMQ4HGSnz4wWSJxgZzcOZs_k8ZItRBq2bqhkVMXtZaBwx gP86WFjkyRrg9CMFNaXKJE4a52ZaJLeZVEBrS1e2WdupaR0f46V4jifeydBw fk4SpAeUxIae.IjjdgcEc72IPVLg14.qfMF33qUBAH24.Oe3oWa.XfxXYW9B WknniccoMBd7TNW9gV6_AIWLE9DXRPHIQwJpbQrmW0YRk5E2hhqZjLGFYijt u.y63TVKZ71csFy1MEZToqPkdpMQ9nKqxIKckX0DIWC3Ix.HonPqAhrXi6r7 hotfoDqHHEjUGSwMDKUQ2gJfAqvpz9nr_cR1Nyq2BxQk5QqS4S6HIwaU4zHF FIpgAgrboshcsqsPZ0cq7OEa_FTR3r6X1Dai1aOR84t4IxLOH.QgSYQOOaJk Q.vPbjDheBSQmYAY- X-Rocket-MIMEInfo: 001.001, CgpXZWxsLCBJJ20gbm90IGFuc3dlcmluZyB5b3VyIHF1ZXN0aW9uIHNpbmNlIEkgYW0gcmV3cml0aW5nIHRoZSBzY3JpcHQsIGJlY2F1c2UgSSBwcmVmZXIgaXQgdGhpcyB3YXkgOikKCmRlZiBhZGRsaW5lKGxpbmUpOgrCoMKgwqAgcmV0dXJuICI8dHI.JXM8L3RyPlxuIiAlIGxpbmUKCmRlZiBhZGRjb2x1bW4oaXRlbSxuYl9jb2x1bW5zKToKwqDCoMKgIGlmIG5iX2NvbHVtbnMgIT0gMzoKwqDCoMKgwqDCoMKgwqAgcmV0dXJuICI8dGQgY29sc3Bhbj0nJXMnPiVzPC90ZD4iICUgKDMgLSBuYl9jb2x1bW5zICsBMAEBAQE- X-Mailer: YahooMailWebService/0.8.129.483 References: <50e97123$0$294$14726298@news.sunsite.dk> <50e97e4c$0$294$14726298@news.sunsite.dk> Date: Sun, 6 Jan 2013 06:01:47 -0800 (PST) From: chaouche yacine Subject: Re: How to modify this script? To: Kurt Hansen , "python-list@python.org" In-Reply-To: <50e97e4c$0$294$14726298@news.sunsite.dk> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="318864283-659537238-1357480907=:76364" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: chaouche yacine List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 111 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1357481051 news.xs4all.nl 6930 [2001:888:2000:d::a6]:33919 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36251 --318864283-659537238-1357480907=:76364 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable =0A=0AWell, I'm not answering your question since I am rewriting the script= , because I prefer it this way :)=0A=0Adef addline(line):=0A=A0=A0=A0 retur= n "%s\n" % line=0A=0Adef addcolumn(item,nb_columns):=0A=A0=A0=A0 i= f nb_columns !=3D 3:=0A=A0=A0=A0=A0=A0=A0=A0 return "%s<= /td>" % (3 - nb_columns + 1, item)=0A=A0=A0=A0 return "%s" % item= =0A=0Aoutput =3D "\n"=0Afor line in file("data.txt"):=0A=A0=A0=A0 it= ems =3D line.strip().split("\t")=0A=A0=A0=A0 columns =3D ""=0A=A0=A0=A0 for= item in items :=0A=A0=A0=A0=A0=A0=A0=A0 columns +=3D addcolumn(item,len(it= ems))=0A=A0=A0=A0 output=A0 +=3D addline(columns)=0A=0A=0Aoutput +=3D ""=0Aprint output=0A=0A=0Aprinted=0A=0A>>>
=0A=0A=0A=0A=0A
Price table
1 Green apple $1
5 Green apples $4
= 10 Green apples $7
=0A>>> =0A=0A=0A= =0A=0A________________________________=0AFrom: Kurt Hansen =0ATo: python-list@python.org =0ASent: Sunday, January 6, 2013 2:38 P= M=0ASubject: Re: How to modify this script?=0A=0ADen 06/01/13 13.58, chaouc= he yacine skrev:=0A> if len(columns) !=3D 3:=0A>=A0 =A0=A0=A0colspan =3D 3 = - len(columns) + 1=0A>=A0 =A0=A0=A0output +=3D '' % (colsp= an) + item + ' '=0A>=0A> I did not test. Use with caution.=0A=0AI've t= ried to put it in several different places in the script, but with =0Ano lu= ck; remember that I'm not experienced, so please tell me exactly =0Awhere i= t's surposed to be inserted. Could you eventually show the =0Acomplete modi= fied script?=0A=0A>=0A> ---------------------------------------------------= ---------------------=0A> *From:* Kurt Hansen =0A> *T= o:* python-list@python.org=0A> *Sent:* Sunday, January 6, 2013 1:42 PM=0A> = *Subject:* How to modify this script?=0A>=0A> http://www.tuxradar.com/conte= nt/save-time-gedit-snippets:=0A>=0A> To convert tab-separated text lines in= to a HTML-table:=0A>=0A> $<=0A> lines =3D $GEDIT_SELECTED_TEXT.split("\n");= =0A> output =3D '\n';=0A>=0A> for line in lines:=0A>=A0 =A0 =A0 out= put +=3D '';=0A>=0A>=A0 =A0 =A0 columns =3D line.split("\t");=0A>=A0 = =A0 =A0 for item in columns:=0A>=A0 =A0 =A0 =A0 =A0 output +=3D '' + i= tem + ' '=0A>=0A>=A0 =A0 =A0 output +=3D '\n';=0A>=0A> output += =3D '';=0A> return output=0A>=A0 >=0A>=0A> I would like to make a = small modification (I'm not a programmer myself).=0A> Let's say I have thes= e lines:=0A>=0A> Price table=0A> 1 Green apple $1=0A> 5 G= reen apples $4=0A> 10 Green apples $7=0A>=0A> Since there= 's only one "field" in the first line, I want this output:=0A>=0A> Price table=0A>=0A> - insted of=0A>=0A> Pri= ce table=0A>=0A> How to? Thank you i advance.=0A> -- Venlig hilse= n=0A> Kurt Hansen=0A> -- http://mail.python.org/mailman/listinfo/python-lis= t=0A>=0A>=0A=0A=0A-- =0AVenlig hilsen=0AKurt Hansen=0A-- =0Ahttp://mail.pyt= hon.org/mailman/listinfo/python-list --318864283-659537238-1357480907=:76364 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
Well, I'm not answering your question since I am rewriting the scri= pt, because I prefer it this way :)

def addline(line):
 &nbs= p;  return "<tr>%s</tr>\n" % line

def addcolumn(ite= m,nb_columns):
    if nb_columns !=3D 3:
  &= nbsp;     return "<td colspan=3D'%s'>%s</td>= ;" % (3 - nb_columns + 1, item)
    return "<td>%s&= lt;/td>" % item

output =3D "<table>\n"
for line in file(= "data.txt"):
    items =3D line.strip().split("\t")
&n= bsp;   columns =3D ""
    for item in items :        columns +=3D addcolumn(item,le= n(items))
    output  +=3D addline(columns)

<= br>output +=3D "</table>"
print output


printed

>>&g= t; <table>
<tr><td colspan=3D'3'>Price table</td>= ;</tr>
<tr><td>1 </td><td> Green apple <= ;/td><td> $1</td></tr>
<tr><td>5 </t= d><td> Green apples </td><td> $4</td></tr>=
<tr><td>10 </td><td> Green apples </td>&l= t;td> $7</td></tr>
</table>
>>>



________________________________
From: Kurt Hansen <kur= t@ugyldig.invalid>
To: python-list@python.org
Sent: Sunday, Janua= ry 6, 2013 2:38 PM
Subject: Re: How to modify this script?

Den 06= /01/13 13.58, chaouche yacine skrev:
> if len(columns) !=3D 3:
>= ;     colspan =3D 3 - len(columns) + 1
>  &n= bsp;  output +=3D '<td colspan=3D%s>' % (colspan) + item + '</td> '
>
> I did not test. Use with caution.

I'= ve tried to put it in several different places in the script, but with
= no luck; remember that I'm not experienced, so please tell me exactly
w= here it's surposed to be inserted. Could you eventually show the
comple= te modified script?

>
> -----------------------------------= -------------------------------------
> *From:* Kurt Hansen <kurt@= ugyldig.invalid>
> *To:* python-list@python.org
> *Sent:* Su= nday, January 6, 2013 1:42 PM
> *Subject:* How to modify this script?=
>
> http://www.tuxradar.com/content/save-time-gedi= t-snippets:
>
> To convert tab-separated text lines into a = HTML-table:
>
> $<
> lines =3D $GEDIT_SELECTED_TEXT.sp= lit("\n");
> output =3D '<table\>\n';
>
> for line in lines:
>      output +=3D '<tr\>';
>>      columns =3D line.split("\t");
>  &nbs= p;   for item in columns:
>          ou= tput +=3D '<td\>' + item + '</td\> '
>
>  &nbs= p;   output +=3D '</tr\>\n';
>
> output +=3D '</t= able\>';
> return output
>  >
>
> I woul= d like to make a small modification (I'm not a programmer myself).
> = Let's say I have these lines:
>
> Price table
> 1 <tab= > Green apple <tab> $1
> 5 <tab> Green apples <tab&= gt; $4
> 10 <tab> Green apples <tab> $7
>
> S= ince there's only one "field" in the first line, I want this output:
>= ;
> <tr><td colspan=3D"3">Price table</td></tr&g= t;
>
> - insted of
>
> <tr><td>Price table</td></tr>
>
> How to? Thank you i advance.> -- Venlig hilsen
> Kurt Hansen
> -- http://mail.p= ython.org/mailman/listinfo/python-list
>
>


-- Venlig hilsen
Kurt Hansen
--
http://mail.python.org/mail= man/listinfo/python-list
--318864283-659537238-1357480907=:76364--