【问题标题】:How to copy specific lines from several .json files, with their source filnames, into another file?如何将多个 .json 文件中的特定行及其源文件名复制到另一个文件中?
【发布时间】:2022-06-16 00:51:28
【问题描述】:

我是编码新手,我只是想看看 是否可以实现,或者是否可以从中编写

基本上,我收到了超过 10000 个文件(扩展名 .json),我必须将行 2021 放入一个文件中,(最好是一个 excel 表,或者另一个 .txt 文件),包含文件名、20 行的内容和21 行的内容。

所以,如果example.json 文件有"hello world" 作为20 行和get(ID) 作为line 21,我需要一些输出:example.json "hello world" get(ID)

我在网上找不到任何东西,可能是因为我不知道从哪里开始。

你们能帮帮我吗?

【问题讨论】:

  • How to select lines to omit from a textfile 展示了如何从文本文件中选择一系列行。您需要更改的只是为每个文件初始化linecount 的方式(即为0),增加行数而不是减少行数,并在循环开始时输出文件名,然后仅当linecount 为20或 21. 输出应附加到结果文件中,并且您不需要像 OP 那样将该文件移到原始文件上。然后更改文件选择标准,SO 上有数千个示例。

标签: python batch-file python json batch-file


猜你喜欢
  • 2017-03-01
  • 2016-03-03
  • 1970-01-01
  • 1970-01-01
  • 2011-07-19
  • 1970-01-01
  • 2013-08-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多