Python中的Unix cat函数(cat *> merged.txt)? [英] Unix cat function (cat * > merged.txt) in Python?

查看:136
本文介绍了Python中的Unix cat函数(cat *> merged.txt)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦建立目录后,是否可以使用Unix或类似方法在Unix中使用cat函数?我想将files_1-3合并到merged.txt

Is there a way to use the cat function from Unix in Python or something similar once a directory has been established ? I want to merge files_1-3 together into merged.txt

我通常只会在Unix中找到目录,然后运行

I would usually just find the directory in Unix and then run

cat * > merged.txt 

file_1.txt
file_2.txt
file_3.txt

merged.txt

推荐答案

我们知道我们将使用"Unix" cat命令(除非您正在寻找pythonic方式或对性能敏感的人)

As we know we are going to use "Unix" cat command (unless you are looking for a pythonic way or being performance concious)

您可以使用

import os
os.system("cd mydir;cat * > merged.txt")

由1_CR指出(谢谢),并在此处进行了说明 Python:如何使用子流程重定向输出?

as pointed by 1_CR (Thanks) and explained here Python: How to Redirect Output with Subprocess?

这篇关于Python中的Unix cat函数(cat *> merged.txt)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆