You can reset the file pointer by calling seek()
:
file.seek(0)
will do it. You need that line after your first readlines()
. Note that file
has to support random access for the above to work.
More Related Contents:
- how to can i go over a file twice?
- open() gives FileNotFoundError/IOError: Errno 2 No such file or directory
- How to check whether a file is empty or not
- How do I get the path and name of the file that is currently executing?
- Sorting text file by using Python
- Skip first couple of lines while reading lines in Python file
- Monitoring contents of files/directories? [duplicate]
- What is the most efficient way to get first and last line of a text file?
- Do I understand os.walk right?
- How do I remove/delete a folder that is not empty?
- Writing a list to a file with Python, with newlines
- How to do virtual file processing?
- Getting file size in Python? [duplicate]
- How do I concatenate files in Python?
- whitespaces in the path of windows filepath
- How to get all of the immediate subdirectories in Python
- Easiest way to persist a data structure to a file in python?
- Python – IOError: [Errno 13] Permission denied:
- Copy multiple files in Python
- Python: read all text file lines in loop
- How to upload File in FastAPI, then to Amazon S3 and finally process it?
- Python – When to use file vs open
- Create a temporary FIFO (named pipe) in Python?
- Pydub (WindowsError: [Error 2] The system can not find the file specified)
- For loop not working twice on the same file descriptor [duplicate]
- f.read coming up empty
- Read random lines from huge CSV file
- What is the difference between .py and .pyc files? [duplicate]
- See if two files have the same content in python [duplicate]
- how to count the total number of lines in a text file using python