小编win*_*boy的帖子

使用 python 和 wc -l 计算文件中的行数

我在 linux 上有这个命令,但type 在 Windows 上转换成问题:

row = run('cat '+'C:/Users/Kyle/Documents/final/VocabCorpus.txt'+" | wc -l").split()[0]
Run Code Online (Sandbox Code Playgroud)

对于语句“wc - l”用于行计数以查看存在多少行。如果我要使用“type”命令将其更改为以下内容,它应该是什么?

我试过这个,但它不起作用。

 row = run('type '+'C:/Users/Kyle/Documents/final/VocabCorpus.txt'+" | wc -l").split()[0]
Run Code Online (Sandbox Code Playgroud)

运行命令如下:

def run(command):
    output = subprocess.check_output(command, shell=True)
    return output
Run Code Online (Sandbox Code Playgroud)

请帮我。谢谢你。

python linux cmd

3
推荐指数
1
解决办法
3546
查看次数

标签 统计

cmd ×1

linux ×1

python ×1