【发布时间】:2016-05-27 03:51:56
【问题描述】:
我正在努力避免这种事情:
sibling_location = os.path.join(leaf_dir, os.pardir, os.pardir, os.pardir, sibling_name)
我觉得这样说会很酷
sibling_location = os.path.join(leaf_dir, *[os.pardir]*3, sibling_name)
但不幸的是,* 参数扩展技巧不允许在它扩展的列表之后有更多参数。
【问题讨论】:
-
不相关:该语法适用于 Python 3.5,请参阅 python.org/dev/peps/pep-0448
-
酷 - 应该是有道理的 :)
标签: python python-2.7 path filesystems