Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81713
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-11-29 00:00 -0800 |
| References | <CADjSo4Ro3xFj9T9gj0NO7YESE6G873vvrBD=Y=OAk-jNBRD5Bw@mail.gmail.com> <5478932A.1030509@davea.name> <m5a67t$qk4$1@ger.gmane.org> <mailman.16418.1417210523.18130.python-list@python.org> |
| Message-ID | <3380ab6f-28b0-49bf-a734-09ce7b880544@googlegroups.com> (permalink) |
| Subject | Re: Iterate over text file, discarding some lines via context manager |
| From | wxjmfauth@gmail.com |
>>> with open('UnicodeData.txt', 'rb') as f:
... t = f.read()
...
>>> t = t.decode('ascii')
>>> z = t.splitlines()
>>> # process
>>> zz = [e.split(';') for e in z]
>>> for e in zz[:3]:
... print(e)
...
['0000', '<control>', 'Cc', '0', 'BN', '', '', '', '', 'N', 'NULL', '', '', '', '']
['0001', '<control>', 'Cc', '0', 'BN', '', '', '', '', 'N', 'START OF HEADING', '', '', '', '']
['0002', '<control>', 'Cc', '0', 'BN', '', '', '', '', 'N', 'START OF TEXT', '', '', '', '']
>>> (len(t), len(z), len(zz))
(1509570, 27268, 27268)
>>>
Fast, simple, unbeatable, (without aspirin).
jmf
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: Iterate over text file, discarding some lines via context manager Akira Li <4kir4.1i@gmail.com> - 2014-11-29 00:33 +0300 Re: Iterate over text file, discarding some lines via context manager wxjmfauth@gmail.com - 2014-11-29 00:00 -0800
csiph-web