

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set read and write position in a file in Python?
You can use the seek(offset[, whence]) method. It sets the file's current position, like stdio's fseek(). The whence argument is optional and defaults to 0 (absolute file positioning); other values are 1 (seek relative to the current position) and 2 (seek relative to the file's end). For example, if there is a file called my_file with text Hello\nworld, and you want to move just before the first l, you can use:
f = open('my_file', 'r') f.seek(2) f.close()
This will seek the pointer to just before the first l.
- Related Questions & Answers
- How to use seek() method to reset a file read/write position in Python?
- How to open a file in read and write mode with Python?
- How to read and write a file using Javascript?
- How to open a binary file in read and write mode with Python?
- Read and Write to an excel file using Python openpyxl module
- Read/Write structure to a file using C
- How to read a text file in Python?
- Write a C program to read a data from file and display
- How to read CSV file in Python?
- How to read JSON file in Python
- How to read/write data from/to .properties file in Java?
- Write a Python program to read an Excel data from file and read all rows of first and last columns
- Read/Write Class Objects from/to File in C++
- How to open a file just to read in python?
- How to open a file to write in Python?
Advertisements