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.


    Missing pathlib.expanduser()?

    Pythonista
    2
    6
    2392
    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.
    • mikael
      mikael last edited by

      With this:

      import pathlib
      p = pathlib.Path('~/Documents')
      p.expanduser()
      

      ... I get a stacktrace:

      AttributeError: 'PosixPath' object has no attribute 'expanduser'
      

      dir(p) shows no trace of expanduser, although it should have been there since 3.5.

      Any ideas why? Something I am doing or A Pythonista quirk?

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

        @mikael no error for me....try restart Pythonista

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

          @cvp, thanks!

          It was a classic case of something having pulled an old version of pathlib.py to site-packages.

          Easy to find by checking pathlib.__file__.

          Deleted & restarted & solved.

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

            @mikael just wanted to say

            print(os.path.dirname(pathlib.__file__)) 
            
            mikael 1 Reply Last reply Reply Quote 0
            • mikael
              mikael @cvp last edited by mikael

              @cvp, I am confused about the added value?

              >>> import pathlib
              >>> pathlib.__file__
              '/var/containers/Bundle/Application/B21D36A1-33F6-45D3-8E39-FFD13E200E5D/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/pathlib.py'
              >>> import os.path
              >>> os.path.dirname(pathlib.__file__)
              '/var/containers/Bundle/Application/B21D36A1-33F6-45D3-8E39-FFD13E200E5D/Pythonista3.app/Frameworks/Py3Kit.framework/pylib'
              
              cvp 1 Reply Last reply Reply Quote 0
              • cvp
                cvp @mikael last edited by

                @mikael Not a big added value 😀 It shows it is part of Pythonista but if you get a folder like site-packages, it proves you have an unwanted copy

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