Can read() and readline() be used together?
<p>Is it possible to use both read() and readline() on one text file in python?</p>

<p>When I did that, it will only do the first reading function.</p>

<pre><code>file = open(name, "r")
inside = file.readline()
inside2 = file.read()

print(name)
print(inside)
print(inside2)
</code></pre>

<p>The result shows only the <code>inside</code> variable, not <code>inside2</code>.</p>

<p>Yes you can.</p>

<p><code>file.readline()</code> reads a line from the file (the first line in this case), and then <code>file.read()</code> reads the rest of the file starting from the <em>seek</em> position, in this case, where <code>file.readline()</code> left off.</p>

<p>You are receiving an empty string with <code>f.read()</code> probably because you reached <em>EOF</em> - End of File immediately after reading the first line with <code>file.readline()</code> implying your file only contains one line.</p>

<p>You can however return to the start of the file by moving the seek position to the start with <code>f.seek(0)</code>.</p>

python