[Tutor] close, but no cigar

Jim Mooney cybervigilante at gmail.com
Mon Jul 22 22:55:21 CEST 2013


On 22 July 2013 13:45, Marc Tompkins <marc.tompkins at gmail.com> wrote:

>
>     inFileName = "/Users/Marc/Desktop/rsp/tree.txt"
>     with open(inFileName, 'r') as inFile:
>         inString = inFile.read().decode('cp437')
>         print inString
>
> I already tried something similar and got an error:

with open('../pytree.txt') as pytree, open('newpytree.txt','w') as pyout:
    for line in pytree:
        for char in line:
            newchar = char.decode('cp437')
            pyout.write(newchar)

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2502' in
position 0: ordinal not in range(128)

What's my error here, since I want to write to a file. I have python(x,y)
so printing that is kind of time-taking and not too illuminating ;')

Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130722/95201807/attachment.html>


More information about the Tutor mailing list