<p>你可以在这里用简单的文件归档。你只需要:</p>
<ul>
<li>打开文件并读取行</li>
<li>使用regex检查星号或任何你想匹配的东西,得到正确的一行</li>
<li>执行操作并相应地覆盖参数</li>
<li>写入文件</li>
</ul>
<h3>代码</h3>
<p>我用了你在报告中提供的数据数据.txt并将结果保存在新建.txt. 下面是我使用的代码。你知道吗</p>
<pre><code>import re
with open('data.txt', 'r') as infile, open('new.txt', 'a') as outfile:
for curr_line in infile:
matchObj = re.match(r'[^*]+\*\*[^*]+\*\*[^*]+', curr_line, re.M | re.I)
if matchObj:
## Perform some stuff and overwrite the row
curr_line = ' Updated Row '
outfile.write(curr_line)
</code></pre>
<h3>结果</h3>
<p>这是我得到的结果</p>
<pre><code>[TITLE]
";;Project Title/Notes"
[OPTIONS]
";;Option Value"
FLOW_UNITS CMS
INFILTRATION CURVE_NUMBER
FLOW_ROUTING DYNWAVE
LINK_OFFSETS DEPTH
MIN_SLOPE 0
ALLOW_PONDING NO
SKIP_STEADY_STATE NO
START_DATE 07/23/2018
START_TIME 00:00:00
REPORT_START_DATE 07/23/2018
REPORT_START_TIME 00:00:00
END_DATE 07/23/2018
END_TIME 06:00:00
SWEEP_START 01/01
SWEEP_END 12/31
DRY_DAYS 0
REPORT_STEP 00:01:00
WET_STEP 00:05:00
DRY_STEP 01:00:00
ROUTING_STEP 0:00:30
INERTIAL_DAMPING PARTIAL
NORMAL_FLOW_LIMITED BOTH
FORCE_MAIN_EQUATION H-W
VARIABLE_STEP 0.75
LENGTHENING_STEP 0
MIN_SURFAREA 1.14
MAX_TRIALS 8
HEAD_TOLERANCE 0.0015
SYS_FLOW_TOL 5
LAT_FLOW_TOL 5
MINIMUM_STEP 0.5
THREADS 1
[EVAPORATION]
";;Data Source Parameters"
";; "
CONSTANT 0.0
DRY_ONLY NO
[OUTFALLS]
";;Name Elevation Type Stage Data Gated Route To "
";; "
OF1 996.1 FREE NO
[STORAGE]
";;Name Elev. MaxDepth InitDepth Shape Curve Name/Params N/A Fevap Psi Ksat IMD "
";; - "
Updated Row Updated Row Updated Row Updated Row
[CONDUITS]
";;Name From Node To Node Length Roughness InOffset OutOffset InitFlow MaxFlow "
";; "
C1 J1 J3 100 0.013 0 1 0 0
C2 J2 J4 100 0.013 0 1 0 0
C3 J3 J4 100 0.013 0 0.9 0 0
C4 J4 OF1 100 0.013 0 0 0 0
[XSECTIONS]
";;Link Shape Geom1 Geom2 Geom3 Geom4 Barrels Culvert "
";; "
C1 CIRCULAR 0.5 0 0 0 1
C2 CIRCULAR 0.5 0 0 0 1
C3 CIRCULAR 0.6 0 0 0 1
C4 CIRCULAR 0.7 0 0 0 1
[INFLOWS]
";;Node Constituent Time Series Type Mfactor Sfactor Baseline Pattern"
";; "
J2 FLOW TR20ANOS FLOW 1.0 1.0
J1 FLOW TR20ANOS FLOW 1.0 1.0
J4 FLOW TR20ANOS FLOW 1.0 1.0
J3 FLOW TR20ANOS FLOW 1.0 1.0
[TIMESERIES]
";;Name Date Time Value "
";; "
TR20ANOS 0:00 0
TR20ANOS 0:01 0.063
TR20ANOS 0:02 0.126
TR20ANOS 0:03 0.190
TR20ANOS 0:04 0.253
TR20ANOS 0:05 0.316
TR20ANOS 0:06 0.379
TR20ANOS 0:07 0.358
TR20ANOS 0:08 0.337
TR20ANOS 0:09 0.316
TR20ANOS 0:10 0.295
TR20ANOS 0:11 0.274
TR20ANOS 0:12 0.253
TR20ANOS 0:13 0.232
TR20ANOS 0:14 0.211
TR20ANOS 0:15 0.190
TR20ANOS 0:16 0.168
TR20ANOS 0:17 0.147
TR20ANOS 0:18 0.126
TR20ANOS 0:19 0.105
TR20ANOS 0:20 0.084
TR20ANOS 0:21 0.063
TR20ANOS 0:22 0.042
TR20ANOS 0:23 0.021
TR20ANOS 0:24 0.000
[REPORT]
";;Reporting Options"
INPUT NO
CONTROLS NO
SUBCATCHMENTS ALL
NODES ALL
LINKS ALL
[TAGS]
[MAP]
DIMENSIONS 0.000 0.000 10000.000 10000.000
Units None
[COORDINATES]
";;Node X-Coord Y-Coord "
";; "
OF1 100.000 0.000
J2 0.000 100.000
J1 0.000 200.000
J4 100.000 100.000
J3 100.000 200.000
[VERTICES]
";;Link X-Coord Y-Coord "
";; "
</code></pre>