plumbum:如何将变量发送到标准输入?

plumbum: How to send a variable to stdin?

我目前在做:

(local['echo'][var] | sth)()

这看起来既不优雅又低效。

我在 plumbum documentation 中找到了解决方案:

您可以使用左移运算符 <<

from plumbum import local

if __name__ == '__main__':
    var = "some text in a python variable"

    sth = local["cat"]

    x = (local['echo'][var] | sth)()
    print(x)

    print("alternative:")
    x = (sth << var)()
    print(x)