lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On Feb 21, 2014, at 22:57 , djczaski@gmail.com wrote:

On Feb 21, 2014, at 4:48 PM, Ren�ebe <rene@exactcode.de> wrote:

On Feb 21, 2014, at 22:29 , djczaski@gmail.com wrote:

I was curious how Python would handle this evil and non portable mess:

    $ cat io.py
    from string import printable

    f = open('foo', 'w')
    for i in range(0, 5):
        f.write("hello\0world\n")

    f = open('foo', 'r')
    for l in f.readlines():
        print ''.join(c if c in printable else '.' for c in l),

    $ python io.py
    hello.world
    hello.world
    hello.world
    hello.world
    hello.world

Instead of doing it right, look for others who do it worse?

It's not doing it worse, it's doing exactly as you would expect. Each line is returned with the embedded '\0'. That's what you expected from Lua, no?

Yes, thank you. I was not that familiar with Python and reading it wrong, � :-/

-- 
 ExactCODE GmbH, Jaegerstr. 67, DE-10117 Berlin
 http://exactcode.com | http://exactscan.com | http://ocrkit.com | http://t2-project.org | http://rene.rebe.de