ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](resource.xhtml "resource --- Resource usage information") | - [上一页](fcntl.xhtml "fcntl --- The fcntl and ioctl system calls") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - [Python 标准库](index.xhtml) » - [Unix 专有服务](unix.xhtml) » - $('.inline-search').show(0); | # [`pipes`](#module-pipes "pipes: A Python interface to Unix shell pipelines. (Unix)") --- Interface to shell pipelines **Source code:** [Lib/pipes.py](https://github.com/python/cpython/tree/3.7/Lib/pipes.py) \[https://github.com/python/cpython/tree/3.7/Lib/pipes.py\] - - - - - - The [`pipes`](#module-pipes "pipes: A Python interface to Unix shell pipelines. (Unix)") module defines a class to abstract the concept of a *pipeline*--- a sequence of converters from one file to another. Because the module uses **/bin/sh** command lines, a POSIX or compatible shell for [`os.system()`](os.xhtml#os.system "os.system") and [`os.popen()`](os.xhtml#os.popen "os.popen") is required. The [`pipes`](#module-pipes "pipes: A Python interface to Unix shell pipelines. (Unix)") module defines the following class: *class* `pipes.``Template`An abstraction of a pipeline. 示例: ``` >>> import pipes >>> t = pipes.Template() >>> t.append('tr a-z A-Z', '--') >>> f = t.open('pipefile', 'w') >>> f.write('hello world') >>> f.close() >>> open('pipefile').read() 'HELLO WORLD' ``` ## Template Objects Template objects following methods: `Template.``reset`()Restore a pipeline template to its initial state. `Template.``clone`()Return a new, equivalent, pipeline template. `Template.``debug`(*flag*)If *flag* is true, turn debugging on. Otherwise, turn debugging off. When debugging is on, commands to be executed are printed, and the shell is given `set -x` command to be more verbose. `Template.``append`(*cmd*, *kind*)Append a new action at the end. The *cmd* variable must be a valid bourne shell command. The *kind* variable consists of two letters. The first letter can be either of `'-'` (which means the command reads its standard input), `'f'` (which means the commands reads a given file on the command line) or `'.'` (which means the commands reads no input, and hence must be first.) Similarly, the second letter can be either of `'-'` (which means the command writes to standard output), `'f'` (which means the command writes a file on the command line) or `'.'` (which means the command does not write anything, and hence must be last.) `Template.``prepend`(*cmd*, *kind*)Add a new action at the beginning. See [`append()`](#pipes.Template.append "pipes.Template.append") for explanations of the arguments. `Template.``open`(*file*, *mode*)Return a file-like object, open to *file*, but read from or written to by the pipeline. Note that only one of `'r'`, `'w'` may be given. `Template.``copy`(*infile*, *outfile*)Copy *infile* to *outfile* through the pipe. ### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](resource.xhtml "resource --- Resource usage information") | - [上一页](fcntl.xhtml "fcntl --- The fcntl and ioctl system calls") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - [Python 标准库](index.xhtml) » - [Unix 专有服务](unix.xhtml) » - $('.inline-search').show(0); | © [版权所有](../copyright.xhtml) 2001-2019, Python Software Foundation. Python 软件基金会是一个非盈利组织。 [请捐助。](https://www.python.org/psf/donations/) 最后更新于 5月 21, 2019. [发现了问题](../bugs.xhtml)? 使用[Sphinx](http://sphinx.pocoo.org/)1.8.4 创建。