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.


    pathlib - pretty neat

    Pythonista
    py3 pathlib
    1
    1
    820
    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.
    • Phuket2
      Phuket2 last edited by Phuket2

      I was looking at doing a file info thingy to put into the wrench menu. I remembered hearing about the pathlib lib on a video i watched recently. I don't know how long pathlib has been around, but i know they have just updated all the std Libs to work nice with pathlib, i guess they didn't before. Anyway, I don't really know the in's and outs, I started playing with PurePath in the same lib. Well when i say I was playing, I was just printing out some of the methods and attrs. I haven't done them all, but it looks pretty nice if you have to play with paths and files.
      Anyway, i just wanted to pass on the info.

      import editor
      from pathlib import Path, PurePath
      
      pp = PurePath(editor.get_path())
      print(pp.parts)
      print('drive:', pp.drive)
      print('root:', pp.root)
      print('anchor:', pp.anchor)
      print('parents:', pp.parents)
      print('parent:', pp.parent)
      print('name:', pp.name)
      print('suffix:', pp.suffix)
      print('suffixes:', pp.suffixes)
      print('stem:', pp.stem)
      print('as_posix():', pp.as_posix())
      print('as_uri():', pp.as_uri())
      print('is_absolute():', pp.is_absolute())
      print('is_reserved():', pp.is_reserved())
      
      1 Reply Last reply Reply Quote 1
      • First post
        Last post
      Powered by NodeBB Forums | Contributors