首页 > 解决方案 > 将 toolz.pipe 与方法一起使用

问题描述

我有一个pipe要从 toolz 中清理的字符串。但似乎我无法弄清楚如何str.replace在管道中应用该方法。这是一个例子:

x = '9\xa0766'

from toolz import pipe
import unidecode

# Can do like this, but don't want to use nesting.
int(unidecode.unidecode(x).replace(" ", ""))


# Wan't to try to do like this, with sequence of steps, applying transformations on previous output.
pipe(x, 
  unidecode.unidecode, 
  replace(" ", ""), 
  int
) # DON'T WORK!! 
# NameError: name 'replace' is not defined

更一般地,请注意 的输出unidecode.unidecode是一个字符串。所以我希望能够对其应用一些字符串方法。

pipe(x, 
  unidecode.unidecode, 
  type
)  # str

用管道可以吗?

标签: pythonpipepipelinetoolz

解决方案


推荐阅读