【发布时间】:2021-03-26 10:05:01
【问题描述】:
希望有人可以提供帮助,因为我对 Python 还很陌生并且有点挣扎。
我需要获取一个文本文件的内容并将其元素提取到另一个文件中,捕获一些行但忽略其他行。例如,这是原始文件的一部分:
input1
name "Bob"
Always_active
next_input
input2
name "Alice"
Sometimes_active
next_input
input3
name "Ted"
Always_active
next_input
input4
name "Albert"
Never_active
next_input
input5
name "Sue"
Always_active
next_input
input6
name "David"
Never_active
next_input
input7
name "Building1"
Always_active
next_input
input8
name "Building2"
Always_active
next_input
input9
name "Building3"
Always_active
next_input
input10
name "Building4"
Always_active
next_input
这就是我希望能够捕捉到的:
input1
name "Bob"
input2
name "Alice"
input3
name "Ted"
input4
name "Albert"
input5
name "Sue"
input6
name "David"
input7
name "Building1"
input8
name "Building2"
input9
name "Building3"
input10
name "Building4"
所以基本上我需要忽略一些行并捕获其余部分。我怎样才能做到这一点?
【问题讨论】:
-
谢谢大家,每个答案都非常有帮助