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.


    I can‘t write a json file in Pythonista

    Pythonista
    4
    8
    5483
    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.
    • Plastefuchs84
      Plastefuchs84 last edited by Plastefuchs84

      Hello I can’t create json file :(:(:(

      import json
      
      numbers = [2, 3, 5, 7, 11, 13]
      
      filename = 'numbers.json'
      
      with open(filename, 'w') as json_f:
      	json.dump(numbers, json_f)
      

      And the same error line with open....

      import json, codecs
      
      numbers = [2, 3, 5, 7, 11, 13]
      
      filename = 'numbers.json'
      
      with open(filename, 'wb') as f:
          json.dump(numbers, codecs.getwriter('utf-8')(f), ensure_ascii=False)
      

      Error message:

      Traceback (most recent call last):
      File "/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/Python examples/number_writer.py", line 7, in <module>
      with open(filename, 'w') as json_f:
      PermissionError: [Errno 1] Operation not permitted: 'numbers.json

      cvp 1 Reply Last reply Reply Quote 0
      • ellie_ff1493
        ellie_ff1493 last edited by

        Doesn’t have to be a dict?

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

          Works fine for me, where are you running the script, it might not have permission to write there

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

            I Use pythonista on iPad Air 2019 and iPhone, and can‘t run the code. :–(

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

              Works for me...

              import json
              
              numbers = [2, 3, 5, 7, 11, 13]
              
              filename = 'numbers.json'
              
              with open(filename, 'w') as json_f:
                  json.dump(numbers, json_f)
              with open(filename) as json_f:
                  print(json.load(json_f) == numbers)
              
              1 Reply Last reply Reply Quote 0
              • cvp
                cvp @Plastefuchs84 last edited by cvp

                @Plastefuchs84 said:

                File "/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/Python examples/number_writer.py

                It is normal, your script is outside Pythonista, thus you are not allowed to create a file

                Edit: move your "Python examples" folder to iCloudDrive/Pythonista3 folder and it will be ok

                1 Reply Last reply Reply Quote 2
                • Plastefuchs84
                  Plastefuchs84 last edited by

                  Ahhhh thanks :-))) it works

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

                    @Plastefuchs84 Welcome here

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