Message220893
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') |
|
Date |
User |
Action |
Args |
2014-06-17 21:10:40 | Gerrit.Holl | set | recipients:
+ Gerrit.Holl |
2014-06-17 21:10:40 | Gerrit.Holl | set | messageid: <1403039440.73.0.798100402294.issue21798@psf.upfronthosting.co.za> |
2014-06-17 21:10:40 | Gerrit.Holl | link | issue21798 messages |
2014-06-17 21:10:40 | Gerrit.Holl | create | |
|