omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Problem reading ascii text

    Pythonista
    5
    6
    2595
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • uncertaintea
      uncertaintea last edited by

      I have a script that reads an ascii encoded text file, created within the Pythonista environment. However, when i execute the script on the text file, i get “error ascii codec cant decode byte 0xe2 in position 2154: ordinal n...”
      Tracking the bug seems to show it to be an error not in .read()

      I try the same script and text file and 20 others like it that i have created on my computer using the stock IDE, and I get no error.

      How can I deal with this?

      I can provide code and text files to recreate the error.

      1 Reply Last reply Reply Quote 0
      • ClackHack
        ClackHack last edited by

        try using encode='utf-8' in the open() function

        uncertaintea 1 Reply Last reply Reply Quote 1
        • Mor3ris
          Mor3ris last edited by Mor3ris

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • ccc
            ccc last edited by ccc

            Try running your script under Python 2.7 instead of Python 3.

            Legacy Python did not make a distinction between bytes and str while Python 3 strictly enforces that distinction.

            1 Reply Last reply Reply Quote 0
            • uncertaintea
              uncertaintea @ClackHack last edited by

              @ClackHack This works, thanks. I still don’t really understand what was going on to cause the encoding error. Isn’t ascii the same as utf-8?

              mikael 1 Reply Last reply Reply Quote 0
              • mikael
                mikael @uncertaintea last edited by

                @uncertaintea, the difference between the two is something I recommend learning a little bit about. See e.g. this article.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors