2
有没有办法链接多个参数的函数?具有多个参数的链接函数
目前我“链”我在Python
操作是这样的:
def createDirIfNecessary(directoryName):
if not os.path.exists(directoryName):
print 'Creating directory [%s]'% directoryName
os.makedirs(directoryName)
return directoryName
cakeName = 'lemonPie'
cookDate = '2011-01-04'
#yewww very ugly, big blob of function call ...
myDir = os.path.join(getDbDir('kitchenCupboardDir'),'cakes', cakeName)
file = os.path.join(createDirIfNecessary(myDir), cookDate + '.gz')
例如,在R
存在使用“管” %>%
运营商进行了非常优雅的方式(管道运营商也出现在Haskell
)。相当的代码是:
cakeName = 'lemonPie'
cookDate = '2011-01-04'
file = getDbDir('kitchenCupboardDir') %>%
file.path('cakes', cakeName) %>%
createDirIfNecessary %>%
file.path(paste0(cookDate,'.gz'))
这里只有4个功能,可以是6,7可以很容易地链接。我不能不幸使用R和我不知道是否有在python 2.7
这是很与此相关的话题,但与其它参数的解决方案: Better way to call a chain of functions in python?