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.


    Pythonista Path Issues

    Pythonista
    path file read file handling open
    4
    4
    434
    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.
    • emily_raye
      emily_raye last edited by

      I am just moving a program that I had previously used on IDLE on Mac to Pythonista and iPad. It pulls files from the directory and reads/writes them. Every time I run this program I get a FileNotFound Error. Even when I use the os.path.abspath() function to determine the file path, then use the open function with the specific path nothing comes up. What folder does my file need to be in to be able to be opened by Pythonista? I’m at the end of my rope. It seems like I’ve tried everything. Any tips would be appreciated!

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

        @emily_raye run this little script in any folder of Pythonista, you will see the full name of its path

        import sys
        print(sys.argv[0])
        

        Something like

        /private/var/mobile/Containers/Shared/AppGroup/1B829014-77B3-4446-9B65-034BDDC46F49/Pythonista3/Documents/MyFolder/myscript.py

        where the numeric part is the id of your iDevice

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

          os.path is kinda old school.

          from pathlib import Path
          my_data = Path(__file__).resolve().parent / "my_file.txt").read_text()
          

          will read the text from a file in the same directory as this Python file.

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

            Are you running your script from an iCloud or external folder perhaps? That is a common problem , that there are a few threads about. IIRC if you want to run from iCloud, you need to create a sub folder.

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