- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the attributes of a file object in Python?
A file object has a lot of attributes. You can see a list of all methods and attributes of the file object here: https://docs.python.org/2.4/lib/bltin-file-objects.html. Following are some of the most used file object methods −
close() - Close the file.
next() - When a file is used as an iterator, typically in a for loop (for example, for line in f: print line), the next() method is called repeatedly. This method returns the next input line, or raises StopIteration when EOF is hit.
read([size]) - Read at most size bytes from the file.
readline([size]) - Read one entire line from the file.
seek(offset[, whence]) - Set 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).
tell() - Return the file's current position, like stdio's ftell().
write(str) - Write a string to the file.
writelines(sequence) - Write a sequence of strings to the file.
Following are file object's most used attributes −
closed - bool indicating the current state of the file object.
encoding - The encoding that this file uses.
mode - The I/O mode for the file.
name - If the file object was created using open(), the name of the file. Otherwise, some string that indicates the source of the file object
- What are the DataTransfer object attributes?
- What are Python function attributes?
- What are the attributes of a Perfect Capital Market?
- What are the attributes in C#?
- What are built-in class attributes in Python?
- What are the attributes of a secure network in information security?
- What are the attributes of programming languages in compiler design?
- Set file attributes in Java
- What are conditional attributes in C#?
- What are obsolete attributes in C#?
- What are predefined attributes in C#?
- What are event attributes in jQuery?
- what are the different attributes of MySQL ENUM data type?
- What are various attributes Of page directive in JSP?
- What are the methods in jQuery to manipulate attributes?