🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.python
Article #27955

Re: zestawienie zbiorcze

#27955
From: Daniel Mróz
Date: Mon, 28 Mar 2011 15:28
67 lines
2472 bytes
On 26.03.2011, Mateuszzz <km_wawaUSUNMNIE@vp.pl> wrote:
> Czy moglbym prosic o szkielet ? Przykladowy skrypt wykonujacy taka 
> operację ?
Nie wiem czy to jest dokładnie to, co chciałeś zrobić w przytoczonym
przez siebie kodzie, ale na szkielet się chyba nada:

[beorn@nika tmp]$ cat data1.txt
1 2 AAA
3 4 BBB
5 6 CCC
[beorn@nika tmp]$ cat data2.txt
1 2
3 4
5 6
[beorn@nika tmp]$ cat test.py
#!/usr/bin/env python
#-*- coding: UTF-8 -*-

import sys


FILE1 = "data1.txt"
FILE2 = "data2.txt"
FILEO = "out.txt"

try:
    fh1 = open(FILE1, 'r')
    fh2 = open(FILE2, 'r')
    fho = open(FILEO, 'w')
except Exception, ex:
    sys.stderr.write('Failed to open file: {0}'.format(': '.join(( str(x) for x in ex.args))))
    sys.exit(1)


while True:
    line1 = fh1.readline().strip('\n')
    line2 = fh2.readline().strip('\n')

    if '' in (line1, line2):
        break

    elements = line1.split(' ')
    if len(elements) != 3:
        sys.stderr.write('Syntax error: {0}\n'.format(elements))
        sys.exit(2)

    fho.write('{0} {1}\n'.format(line2, elements[2]))

fh1.close()
fh2.close()
fho.close()
[beorn@nika tmp]$ python test.py
[beorn@nika tmp]$ cat out.txt
1 2 AAA
3 4 BBB
5 6 CCC



Pozdrawiam
Beorn

-- 
Daniel 'Beorn' Mróz <beorn@alpha.pl>    http://127.0.0.1/beorn
[GIT d s:- a-@ C++++ UL++++$ P+ L++++ E--- W+ N+++ o? K- w---]
[O- M- V!  PS+ PE++ Y+ PGP++ t- 5  X R !tv b+ DI D++ G++ e h*]
[                          r++  y+                           ]
Technical Details
Message-ID: <slrnip1a8a.dpj.beorn@pino.cyberdeck.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.nask.pl!news.nask.org.pl!nntp.aster.pl!newsread.aster.pl!not-for-mail
References: <4d8846a1$0$2438$65785112@news.neostrada.pl> <4d889f2d$0$2455$65785112@news.neostrada.pl> <4d8e2065$0$2456$65785112@news.neostrada.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.nask.pl!news.nask.org.pl!nntp.aster.pl!newsread.aster.pl!not-for-mail
From: Daniel Mróz <beorn@alpha.pl>
Newsgroups: pl.comp.lang.python
Subject: Re: zestawienie zbiorcze
Date: Mon, 28 Mar 2011 15:28:10 +0000 (UTC)
Organization: A tak se walimy młotkami d:-/
Lines: 67
Message-ID: <slrnip1a8a.dpj.beorn@pino.cyberdeck.pl>
References: <4d8846a1$0$2438$65785112@news.neostrada.pl> <4d889f2d$0$2455$65785112@news.neostrada.pl> <4d8e2065$0$2456$65785112@news.neostrada.pl>
NNTP-Posting-Host: 62.121.127.190
Mime-Version: 1.0
X-Trace: newsread.aster.pl 1301326090 9835 62.121.127.190 (28 Mar 2011 15:28:10 GMT)
X-Complaints-To: abuse@aster.pl
NNTP-Posting-Date: Mon, 28 Mar 2011 15:28:10 +0000 (UTC)
User-Agent: slrn/0.9.8.1pl2.1 (Linux)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit