Path: csiph.com!feeder.erje.net!2.eu.feeder.erje.net!feed.usenet.farm!feeder4.usenet.farm!border1.nntp.ams1.giganews.com!nntp.giganews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.fr7!futter-mich.highwinds-media.com!news.highwinds-media.com!fx27.am4.POSTED!not-for-mail Received-SPF: unknown (Address does not pass the Sender Policy Framework) SPF=MAILFROM; sender=macek@sandbox.cz; remoteip=::ffff:87.236.197.188; remotehost=; helo=mx.sandbox.cz; receiver=hugo.zagamma.cz; From: =?UTF-8?B?VmzDocSPYSBNYWNlaw==?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <013c3421-291d-48d1-ade6-5fff922dc88e@googlegroups.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: cs Received-SPF: unknown (Address does not pass the Sender Policy Framework) SPF=FROM; sender=macek@sandbox.cz; remoteip=::ffff:87.236.197.188; remotehost=; helo=mx.sandbox.cz; receiver=hugo.zagamma.cz; Subject: Re: [python] Buducnost Pythonu: lambda, map, filter X-BeenThere: python@py.cz X-Mailman-Version: 2.1.24 Precedence: list List-Id: Konference PyCZ List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: cz.comp.lang.python Message-ID: X-Mailman-Original-Message-ID: <1a690406-a8a3-7fae-bbcf-fecad32273b0@sandbox.cz> X-Mailman-Original-References: <013c3421-291d-48d1-ade6-5fff922dc88e@googlegroups.com> References: <013c3421-291d-48d1-ade6-5fff922dc88e@googlegroups.com> <1a690406-a8a3-7fae-bbcf-fecad32273b0@sandbox.cz> Lines: 78 X-Complaints-To: abuse@usenet-news.net NNTP-Posting-Date: Wed, 13 Dec 2017 09:28:17 UTC Organization: usenet-news.net Date: Wed, 13 Dec 2017 10:28:08 +0100 X-Received-Bytes: 3683 X-Received-Body-CRC: 3613748798 X-Original-Bytes: 3632 Xref: csiph.com cz.comp.lang.python:3220 Ano! A je to pěkná ukázka stability jazyka, není-liž pravda? Nabízím ještě tvořivě generátor sad buněk dělených tabulátorem. :-) line_cells = (line.split('\t') for line in open('data.txt')) Po konzumaci generátoru se soubor sám zavře (Python 2.7.12 i 3.5.2). To samé platí i pro `for line in open(...):`. Hezké Vánoce, V. On 13.12.2017 10:02, Pavel Schön wrote: > Děkujeme za oživení 11 let starého vlákna, na tyto věci se prostě nesmí zapomenout... :-) > > Dne úterý 12. prosince 2017 13:51:54 UTC+1 Petr Mach napsal(a): >> Dnes je ještě lepší toto: >> with open('data.txt') as f: >>     for line in f: >>         print line >> >> >> >> Dne 31. 3. 2017 13:35 napsal uživatel "Petr Přikryl" : >> Roman Miklos napsal(a): >> >> >> Radsej by som naopak uvital keby sa preberalo stale viac, napriklad keby >> >> bolo mozne namiesto >> >> >> >> f = open("data.txt") >> >> line = f.readline() while line: >> >>   print line >> >>   line = f.readline() >> >> f.close() >> >> >> >> napisat jednoducho ako v Perle a C++ >> >> >> >> f = open("data.txt") >> >> while line = f.readline(): >> >>   print line f.close() >> >> >> >> >> Já raději píšu >> >> >> >> f = open("data.txt") >> >> for line in f: >> >>     print line >> >> f.close() >> >> >> >> >> >> pepr