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.


    Editor Module Question

    Pythonista
    editor module openfile
    3
    3
    2552
    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.
    • procryon
      procryon last edited by

      Hey all, quick question about the editor module here. For the .openfile() function, it gives me an error when I put the name of the file I want to open. After reading on the forum, it says to use the filepath. As much as I tried to find a way, I’ve not been able to get the filepath. The file is just in a folder called Brain. Thanks in advance.

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

        import os
        os.path.expanduser('~/Documents/Brain/yourfile.txt')

        1 Reply Last reply Reply Quote 0
        • Phuket2
          Phuket2 @procryon last edited by Phuket2

          @procryon, my example is same as @JonB , except I just split it up so you see the root dir for Pythonista etc. Functionally the same. Just more step by step

          import os
          _root_path = os.path.expanduser('~/Documents')
          _my_dir = 'Brain'
          _my_file_name = 'yourfile.txt'
          
          my_path = os.path.join(_root_path, _my_dir, _my_file_name)
          
          print(my_path)
          
          with open(my_path, "w") as f:
              f.writelines("Hello World")
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors