【发布时间】:2009-11-28 08:54:12
【问题描述】:
我在程序中的路径上使用 os.path.split() 函数来获取文件的文件名和路径名,然后将它们传递给另一个方法,但我目前的解决方案似乎相当难看:
path = os.path.split(somefile)
some_class(path[0], path[1])
是否可以在调用 some_class 时以更简洁的方式解包路径元组?比如:
some_class(os.path.split(somefile).unpack())
或者我应该以另一种方式来解决这个问题?也许是一种更 Pythonic 的方式?
【问题讨论】:
标签: python tuples iterable-unpacking