Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 具有多个参数的链接函数_Python_R_Python 2.7_Functional Programming_Chain - Fatal编程技术网

Python 具有多个参数的链接函数

Python 具有多个参数的链接函数,python,r,python-2.7,functional-programming,chain,Python,R,Python 2.7,Functional Programming,Chain,有没有一种方法可以链接具有多个参数的函数 目前,我在Python中以如下方式“链接”我的操作: def createDirIfNecessary(directoryName): if not os.path.exists(directoryName): print 'Creating directory [%s]'% directoryName os.makedirs(directoryName) return directoryName cak

有没有一种方法可以链接具有多个参数的函数

目前,我在
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
中,有一种非常优雅的方法可以使用“pipe”
%%>%%
操作符(pipe操作符也出现在
Haskell
中)。等效代码为:

cakeName = 'lemonPie'
cookDate = '2011-01-04'

file = getDbDir('kitchenCupboardDir') %>%
         file.path('cakes', cakeName) %>%
         createDirIfNecessary %>%
         file.path(paste0(cookDate,'.gz'))
这里只有4个函数,可以有6个,7个,可以轻松链接。不幸的是,我不能使用R,我想知道在
Python2.7中是否有解决方案

这与本主题非常相关,但有进一步的论据:

fn
包中有
>
操作符和许多其他函数编程的好东西。您可以用python进行函数式编程,即使()这并不是最佳方式。Python可以通过以下方法“链接”函数:

file = getDbDir(...).makePath(...).createDir(...).getPath(...)
这是连锁经营的一种方式