Python Forum
PurePath.relative_to() fails in 3.6
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PurePath.relative_to() fails in 3.6
#2
I know this. This is s****

You have to use os.path.relpath.

Type 'copyright', 'credits' or 'license' for more information
IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import os                                                                                                                       

In [2]: os.path.relpath('/home/andre/test', '/etc/systemd/system/')                                                                     
Out[2]: '../../../home/andre/test'

In [3]:                                                                                                                                 

In [3]: os.path.relpath('/etc/systemd/system/', '/home/andre/test')                                                                     
Out[3]: '../../../etc/systemd/system'

In [4]: os.path.relpath?                                                                                                                
Signature: os.path.relpath(path, start=None)
Docstring: Return a relative version of a path
File:      ~/.pyenv/versions/3.7.4/lib/python3.7/posixpath.py
Type:      function

In [5]:  
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
PurePath.relative_to() fails in 3.6 - by Skaperen - Sep-30-2019, 04:19 AM
RE: PurePath.relative_to() fails in 3.6 - by DeaD_EyE - Sep-30-2019, 07:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Path or PurePath Skaperen 2 7,990 Jul-06-2018, 02:06 AM
Last Post: Skaperen
  Path.relative_to() and symlinks Skaperen 0 2,888 Jun-07-2018, 03:19 AM
Last Post: Skaperen
  getting a full path string from a pathlib.PurePath object Skaperen 14 158,628 Mar-24-2018, 03:55 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020