In Python, how can I get a line number corresponding to a given character location?
<p>If I have a text that I've read into memory by using <code>open('myfile.txt').read()</code>, and if I know a certain location in this file, say, at character 10524, how can I find the line number of that location? </p>

<p>Examine the text preceding your desired position and count the number of <code>\n</code> characters.</p>

python