擅长:python、mysql、java
<p>只需在读取原始行的同时写入一个新文件,根据<em>Stud\u ID</em>值有条件地更改行。新文件的后缀名为New</em>。</p>
<pre><code>line_replace = stud_ID +','+ stud_name +','+ stud_course +','+ stud_year
with open(fileName, 'r') as readFile, open(fileName.replace('.csv', '_new.csv'), 'w') as writeFile:
for row in readFile:
if row[0:9] == stud_ID:
writeFile.write(line_replace)
msg = Label(upd_win, text="Updated Successful", font="fixedsys 12 bold").place(x=3,y=120)
else:
writeFile.write(row)
</code></pre>