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.


    .readline() not working

    Pythonista
    not working readline readlines
    3
    8
    1566
    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.
    • 810D
      810D last edited by

      I tried opening and reading from a csv file with .readline() but it didn’t work.

      I searched it up on the internet, installed stash but stash couldn’t pip install it either.
      I couldn’t find any solution to install it manually.

      Any help is appreciated.

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

        Did you mean .readlines()?

        Maybe show us your script

        1 Reply Last reply Reply Quote 0
        • 810D
          810D last edited by

          I tried both .readline() and .readlines()

          My script isn’t anything fancy

          import csv
          file=open("menu.csv","r").readlines()
          print(file.Readline())

          Neither is working

          cvp 1 Reply Last reply Reply Quote 0
          • cvp
            cvp @810D last edited by

            @810D try

            with open('menu.csv', mode='rt') as fil:
            	lines = fil.readlines()
            
            1 Reply Last reply Reply Quote 0
            • 810D
              810D last edited by 810D

              I tried but it still gives me a UnicodeDecodeError on the line with .readlines()

              Edit: Here is the Error:
              Traceback (most recent call last):
              File "/private/var/mobile/Containers/Shared/AppGroup/8D3D7AE1-1CB4-436D-B202-B8EBCDA65D5F/Pythonista3/Documents/mcdonalds.py", line 6, in <module>
              lines = fil.readlines()
              File "/var/containers/Bundle/Application/25DCAAA8-B420-4833-8B49-78EB3B0BD979/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/encodings/ascii.py", line 27, in decode
              return codecs.ascii_decode(input, self.errors)[0]
              UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 3461: ordinal not in range(128)

              cvp 1 Reply Last reply Reply Quote 0
              • cvp
                cvp @810D last edited by

                @810D ok, errors on special characters like emoji, try

                with open('menu.csv', mode='rt', encoding='utf-8', errors="surrogateescape") as fil:
                
                1 Reply Last reply Reply Quote 0
                • 810D
                  810D last edited by

                  Thank you so much, it is working.

                  cvp 1 Reply Last reply Reply Quote 0
                  • cvp
                    cvp @810D last edited by

                    @810D 👍 and welcome in this marvelous forum of a marvelous app

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