Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36262

Re: How to modify this script?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!hq-usenetpeers.eweka.nl!81.171.88.250.MISMATCH!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <yacinechaouche@yahoo.com>
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; 'python,': 0.02; 'interpreter': 0.04; 'output': 0.04; 'modify': 0.05; 'convention.': 0.07; 'subject:How': 0.09; 'python': 0.09; '"%s"': 0.09; '%s\\n"': 0.09; 'answering': 0.09; 'script,': 0.09; 'subject:script': 0.09; 'def': 0.10; 'kurt': 0.11; 'columns': 0.16; 'item)': 0.16; 'rewriting': 0.16; 'script?': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'to:name:python-list@python.org': 0.20; '&gt;&gt;&gt;': 0.22; 'skip:$ 20': 0.22; 'skip:% 10': 0.22; 'sorry,': 0.22; '&gt;': 0.23; 'to:2**1': 0.23; 'header:In-Reply- To:1': 0.25; 'skip:" 20': 0.26; 'question': 0.27; 'lines': 0.28; 'run': 0.28; 'received:98.138.87': 0.29; 'url:mailman': 0.29; 'skip:& 10': 0.29; "i'm": 0.29; 'worked': 0.30; 'code': 0.31; 'url:python': 0.32; 'file': 0.32; 'running': 0.32; 'skip:_ 30': 0.32; 'print': 0.32; 'url:listinfo': 0.32; 'surely': 0.33; 'to:addr:python-list': 0.33; 'skip:& 20': 0.33; 'that,': 0.34; "can't": 0.34; 'text': 0.34; 'reply-to:addr:yahoo.com': 0.34; 'table': 0.35; 'subject:?': 0.35; 'subject:': 0.36; 'url:org': 0.36; 'apple': 0.36; 'data.': 0.36; 'email addr:python.org': 0.36; 'should': 0.36; 'item': 0.37; 'sent:': 0.37; 'subject:: ': 0.38; 'green': 0.38; 'from:': 0.38; 'skip:l 20': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'help': 0.40; 'url:mail': 0.40; 'your': 0.60; 'you.': 0.61; 'containing': 0.61; 'email name:python-list': 0.62; 'between': 0.63; 'price': 0.66; 'header:Reply-To:1': 0.68; 'business': 0.70; 'received:41': 0.73; 'subject:this': 0.84; '2013': 0.84; 'fortunately': 0.84; 'yourself?': 0.84
X-Yahoo-Newman-Property ymail-3
X-Yahoo-Newman-Id 668118.95638.bm@omp1002.mail.ne1.yahoo.com
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1357485163; bh=qAqz2VmxXcXUIbvqayRRVB4gZcJVb9GbrAyE4YzW+98=; 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=Kf9iqxQ3AtSbmvFDwirwfz+RT46HTGWNBf5TwfLXk5WRrwPHlTkEIj8bHYAIeMbsYpKo1JB1oSrAnJXUSN6g78AJQpGr18NIKa+UQ2Ck19C50XTwDPwRMrJdv+w3RmsSbJHfL+N49wGC8MohvyZ7XS8Bf7Lg4txVxlH3JJb3gKU=
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=4Rr4rQnxRT63adeHc8d6rO5UjM/1zVxs2WoF2dBOQPV6kEhWvl5Orkk+drvzKXdjxU92ItZFN/BvWgMNJmgz3TQV54fuAAH3Knu8OqDtKb7zCWJspXm61wjHAJAG08HCq5N+/a4uR4Pffcq3QLdyuy8eUYVnENQVAjuYEBsAtD4=;
X-YMail-OSG IPBgmiEVM1kNvvBJd5rZ1EzG5eObBQrF5xIW9_07xN7b8fq w4nzJ5chthxVE5OimlCfPEmVGDO4fFgfmcesyan41m0hqV4sZn2_.8ShTOO_ 9rUIiJvRYjIbL0USFHdgYq_YTVG.C7IXz9_GGC_syZh052vb2s7aK0OqM6Kv pRncUcnOYzBRkbxSqUdOgJpaGluVI05B2pTUHBO0Z1MPZvbAgfaCRFQUiTgl 2aBkDyr1YJc9IpmbRmB.0VJl7QK4A9RdP1eTsiO0Hklkn6YA_DTy5PYBOMqH 8aBJUwPSGL7ejg1svwLZ76Kpm_1yO7maPqllcngIV5q69yF9YfzM7GxaDF4E MjdezO0EEXHPUqHY5EeGFEJqERNe_CJQ8.VUf9I8.7qzSiX7Tax9YqDw7mR8 wUc454heAD73Os.ftwBYHkacwgIhEJT8Zg9871_0wEun_Ecv7CyKj_03LyF0 .bPS8wDEmQmvDxt6LvGFy6lWTKCqd8ZW5niFlsaOYJc7Wb_alVdW_HX5oSl7 nd7W9gLP2AfFtF7_c1lPYmZsU2_pi
X-Rocket-MIMEInfo 001.001, SSdtIG5vdCBjb25maWRlbnQgdGhpcyB3b3VsZCBydW4gb24gZ2VkaXQuIEl0IHdvcmtzIG9uIGEgcHl0aG9uIGludGVycHJldGVyIGlmIHlvdSBoYXZlIGEgZmlsZSBuYW1lZCBkYXRhLnR4dCBpbiB0aGUgc2FtZSBkaXJlY3RvcnkgY29udGFpbmluZyB5b3VyIHNhbXBsZSBkYXRhLgoKSXQgc3VyZWx5IGhhcyB0byBkbyB3aXRoIGhvdyBnZWRpdCB3b3JrcyB0aGVuLCBiZWNhdXNlIHRoZSAiJCIgc2lnbiBpc24ndCB1c2VkIGluIHB5dGhvbiwgdGhpcyBidXNpbmVzcyBzaG91bGQgYmUgYSBnZWRpdCBjb252ZW4BMAEBAQE-
X-Mailer YahooMailWebService/0.8.129.483
References <50e97123$0$294$14726298@news.sunsite.dk> <mailman.161.1357477260.2939.python-list@python.org> <50e97e4c$0$294$14726298@news.sunsite.dk> <mailman.168.1357481051.2939.python-list@python.org> <50e9885e$0$294$14726298@news.sunsite.dk>
Date Sun, 6 Jan 2013 07:12:43 -0800 (PST)
From chaouche yacine <yacinechaouche@yahoo.com>
Subject Re: How to modify this script?
To Kurt Hansen <kurt@ugyldig.invalid>, "python-list@python.org" <python-list@python.org>
In-Reply-To <50e9885e$0$294$14726298@news.sunsite.dk>
MIME-Version 1.0
Content-Type multipart/alternative; boundary="264668936-1014338162-1357485163=:11230"
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To chaouche yacine <yacinechaouche@yahoo.com>
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.173.1357485172.2939.python-list@python.org> (permalink)
Lines 78
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1357485172 news.xs4all.nl 6965 [2001:888:2000:d::a6]:42335
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:36262

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

I'm not confident this would run on gedit. It works on a python interpreter if you have a file named data.txt in the same directory containing your sample data.

It surely has to do with how gedit works then, because the "$" sign isn't used in python, this business should be a gedit convention. And sorry, I can't help on that, I'm not a user of gedit myself. Fortunately others have answered and I beleive one of the solutions worked for you.



________________________________
 From: Kurt Hansen <kurt@ugyldig.invalid>
To: python-list@python.org 
Sent: Sunday, January 6, 2013 3:21 PM
Subject: Re: How to modify this script?
 
Den 06/01/13 15.01, chaouche yacine wrote:
> Well, I'm not answering your question since I am rewriting the script,
> because I prefer it this way :)
> 
> def addline(line):
>      return "<tr>%s</tr>\n" % line
[cut]

I surpose I shall put your code between $< and >?

> printed
> 
>  >>> <table>
> <tr><td colspan='3'>Price table</td></tr>
> <tr><td>1 </td><td> Green apple </td><td> $1</td></tr>
> <tr><td>5 </td><td> Green apples </td><td> $4</td></tr>
> <tr><td>10 </td><td> Green apples </td><td> $7</td></tr>
> </table>
>  >>>

Aha, so you tested it yourself?

When running this in Gedit on four lines of tab-separated text the output is:

%s</tr>\n" % line

def addcolumn(item,nb_columns):
    if nb_columns != 3:
        return "<td colspan='%s'>%s</td>" % (3 - nb_columns + 1, item)
    return "<td>%s</td>" % item

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


output += "</table>"
print output
>
-- Venlig hilsen
Kurt Hansen
-- http://mail.python.org/mailman/listinfo/python-list

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to modify this script? Kurt Hansen <kurt@ugyldig.invalid> - 2013-01-06 13:42 +0100
  Re: How to modify this script? Chris Angelico <rosuav@gmail.com> - 2013-01-06 23:52 +1100
    Re: How to modify this script? Kurt Hansen <kurt@ugyldig.invalid> - 2013-01-06 14:34 +0100
      Re: How to modify this script? Chris Angelico <rosuav@gmail.com> - 2013-01-07 00:44 +1100
        Re: How to modify this script? Kurt Hansen <kurt@ugyldig.invalid> - 2013-01-06 15:03 +0100
          Re: How to modify this script? Chris Angelico <rosuav@gmail.com> - 2013-01-07 01:20 +1100
            Re: How to modify this script? Kurt Hansen <kurt@ugyldig.invalid> - 2013-01-06 15:30 +0100
              Re: How to modify this script? Chris Angelico <rosuav@gmail.com> - 2013-01-07 01:41 +1100
              Re: How to modify this script? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2013-01-08 15:18 +0100
                Re: How to modify this script? Kurt Hansen <kurt@ugyldig.invalid> - 2013-01-09 10:21 +0100
  Re: How to modify this script? chaouche yacine <yacinechaouche@yahoo.com> - 2013-01-06 04:58 -0800
    Re: How to modify this script? Kurt Hansen <kurt@ugyldig.invalid> - 2013-01-06 14:38 +0100
      Re: How to modify this script? chaouche yacine <yacinechaouche@yahoo.com> - 2013-01-06 06:01 -0800
        Re: How to modify this script? Kurt Hansen <kurt@ugyldig.invalid> - 2013-01-06 15:21 +0100
          Re: How to modify this script? chaouche yacine <yacinechaouche@yahoo.com> - 2013-01-06 07:12 -0800
            Re: How to modify this script? Kurt Hansen <kurt@ugyldig.invalid> - 2013-01-07 17:42 +0100
              Re: How to modify this script? chaouche yacine <yacinechaouche@yahoo.com> - 2013-01-08 07:31 -0800
                Re: How to modify this script? Kurt Hansen <kurt@ugyldig.invalid> - 2013-01-09 10:07 +0100
                Re: How to modify this script? chaouche yacine <yacinechaouche@yahoo.com> - 2013-01-09 02:23 -0800
                Re: How to modify this script? Kurt Hansen <kurt@ugyldig.invalid> - 2013-01-09 12:04 +0100
                Re: How to modify this script? chaouche yacine <yacinechaouche@yahoo.com> - 2013-01-09 10:25 -0800
                Re: How to modify this script? Kurt Hansen <kurt@ugyldig.invalid> - 2013-01-11 05:35 +0100
  Re: How to modify this script? Subimal Deb <subimal.deb@gmail.com> - 2013-01-06 06:22 -0800
    Re: How to modify this script? Kurt Hansen <kurt@ugyldig.invalid> - 2013-01-06 15:40 +0100
      Re: How to modify this script? Chris Angelico <rosuav@gmail.com> - 2013-01-07 01:52 +1100
        Re: How to modify this script? Kurt Hansen <kurt@ugyldig.invalid> - 2013-01-06 16:05 +0100
  Re: How to modify this script? Gertjan Klein <gklein@xs4all.nl> - 2013-01-07 18:56 +0100
    Re: How to modify this script? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2013-01-08 15:22 +0100
      Re: How to modify this script? Gertjan Klein <gklein@xs4all.nl> - 2013-01-08 17:22 +0100

csiph-web