mate_mutate_methods#
Provide methods to mutate the Path instance.
- class pathlib_mate.mate_mutate_methods.MutateMethods[source]#
Provide methods to mutate the Path instance.
- drop_parts(n=1)[source]#
Drop number of parts from the ends. By default, it is equal to
self.parent
.Example:
>>> Path("/usr/bin/python").drop_parts(1) "/user/bin" >>> Path("/usr/bin/python").drop_parts(2) "/user"
- append_parts(*parts)[source]#
Append some parts to the end of this path.
Example:
>>> Path("/usr/bin/python").append_parts("lib") "/user/bin/python/lib" >>> Path("/usr/bin/python").append_parts("lib", "core.py") "/user/bin/python/lib/core.py"
- Return type:
- Returns:
a new Path object.
- change(new_abspath=None, new_dirpath=None, new_dirname=None, new_basename=None, new_fname=None, new_ext=None)[source]#
Return a new
pathlib_mate.pathlib2.Path
object with updated path.Example:
>>> Path("/Users/alice/test.py").change(new_fname="test1") /Users/alice/test1.py >>> Path("/Users/alice/test.py").change(new_ext=".txt") /Users/alice/test.txt >>> Path("/Users/alice/test.py").change(new_dirname="bob") /Users/bob/test.py >>> Path("/Users/alice/test.py").change(new_dirpath="/tmp") /tmp/test.py
- Return type:
中文文档
高级重命名函数, 允许用于根据路径的各个组成部分进行重命名. 但和 os.rename 方法一样, 需要保证母文件夹存在.
- is_not_exist_or_allow_overwrite(overwrite=False)[source]#
Test whether a file target is not exists or it exists but allow overwrite.
- Parameters:
overwrite – bool
- Return type:
- moveto(new_abspath=None, new_dirpath=None, new_dirname=None, new_basename=None, new_fname=None, new_ext=None, overwrite=False, makedirs=False)[source]#
Similar to
change()
method. However, it move the original path to new location.- Return type:
中文文档
高级 文件 / 文件夹 移动函数, 允许用于根据路径的各个组成部分进行重命名, 然后移动.
- copyto(new_abspath=None, new_dirpath=None, new_dirname=None, new_basename=None, new_fname=None, new_ext=None, overwrite=False, makedirs=False)[source]#
Similar to
change()
method. However, it copy the original path to new location.- Return type:
中文文档
高级 文件 / 文件夹 拷贝函数, 允许用于根据路径的各个组成部分进行重命名, 然后拷贝.
- classmethod dir_here(file_var)[source]#
Return the directory of the python script that where this method is called.
Suppose you have a file structure like this:
/Users/myname/test.py
And it is the content of
test.py
:from pathlib_mate import Path dir_here = Path.dir_here(__file__) print(dir_here) # /Users/myname