擅长:python、mysql、java
<p>要更改文件的特定行时获取当前位置的方法:</p>
<pre><code>cp = 0 # current position
with open("my_file") as infile:
while True:
ret = next(infile)
cp += ret.__len__()
if ret == string_value:
break
print(">> Current position: ", cp)
</code></pre>