This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Gerrit.Holl
Recipients Gerrit.Holl
Date 2014-06-17.21:10:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1403039440.73.0.798100402294.issue21798@psf.upfronthosting.co.za>
In-reply-to
Content
It would be great if we could "add" either str or Path to Path objects.  Currently, we can join paths only by adding a directory, or by replacing the suffix.  But sometimes we want to build up a path more directly.  With strings we can do that simply by concatenating strings.  It would be great if we could do the same with Path objects, like this:

In [2]: b = pathlib.Path("/tmp/some_base")

In [3]: b + "_name.dat"
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-939467ea0aa5> in <module>()
----> 1 b + "_name.dat"

TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str'

In [4]: b + pathlib.Path("_name.dat")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-460bf8ac7710> in <module>()
----> 1 b + pathlib.Path("_name.dat")

TypeError: unsupported operand type(s) for +: 'PosixPath' and 'PosixPath'

In [11]: b.with_name(b.name + "_name.dat")  # desired effect
Out[11]: PosixPath('/tmp/some_base_name.dat')
History
Date User Action Args
2014-06-17 21:10:40Gerrit.Hollsetrecipients: + Gerrit.Holl
2014-06-17 21:10:40Gerrit.Hollsetmessageid: <1403039440.73.0.798100402294.issue21798@psf.upfronthosting.co.za>
2014-06-17 21:10:40Gerrit.Holllinkissue21798 messages
2014-06-17 21:10:40Gerrit.Hollcreate