Python arrays and sting formatting options

Ivan Reborin ireborin at
Tue Sep 30 15:42:58 CEST 2008

On 30 Sep 2008 07:07:52 GMT, Marc 'BlackJack' Rintsch <bj_666 at>

Hello Marc, thanks for answering (on both subjects). I understand now
the logic which lays behind what you were explaining in the other one.
It cleared things quite a bit.

>Well, I don't know if this qualifies as equivalent:
>from __future__ import with_statement
>from functools import partial
>from itertools import islice
>from pprint import pprint
>def read_group(lines, count):
>    return [map(int, s.split()) for s in islice(lines, count)]
>def main():
>    result = list()
>    with open('test.txt') as lines:
>        lines = (line for line in lines if line.strip())
>        result = list(iter(partial(read_group, lines, 3), list()))
>    pprint(result, width=30)
>if __name__ == '__main__':
>    main()

I'm afraid I must admit I find the code above totally uncomprehesible
(I can't even see where the array here is mentioned - "result"?) and
inpractical for any kind of engineering practice I had in mind.

Does python, perchance, have some wrapper functions or something,
which would allow one to load an array in a more natural "technical"
way ? Like something mentioned above in my post (now deleted) ?

Also, is there a way to change counter for arrays to go from 0 to 1 ?
(first element being with the index 1) ?
(probably not since that seems like a language implementation thing,
but it doesn't hurt to ask)


More information about the Python-list mailing list