- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 is the difference between os.open and os.fdopen in python?
File descriptors are a low-level facility for working with files directly provided by the OS kernel. A file descriptor is an integer that identifies the open file in a table of open files kept by the kernel for each process. A number of system calls accept file descriptors, but they are not convenient to work with, typically requiring fixed-width buffers, multiple retries in certain conditions, and manual error handling.
File objects are Python classes that wrap file descriptors to make working with files more convenient and less error-prone. For example, they provide error-handling, buffering, line-by-line reading and are closed when garbage collected.
Built-in open() takes a file name and returns a new Python file object. Note that this is different from os.open()
os.open() takes a file name and returns a new file descriptor. This file descriptor can be passed to other low-level functions, such as os.read() and os.write(), or to os.fdopen().
os.fdopen() takes an existing file descriptor and builds a Python file object around it. It converts a file descriptor to a full file object. It is useful when interfacing with C code or with APIs that only create low-level file descriptors.
So both of these functions provide more close to the system functionality to work with in Python.
- Related Articles
- What is the difference between = and == operators in Python?
- What is the Difference Between Scala and Python?
- What is the difference between the != and operators in Python?
- What is the difference between Core Python and Django Python?
- What is the difference between attributes and properties in python?
- What is the difference between __str__ and __repr__ in Python?
- What is the difference between dict.items() and dict.iteritems() in Python?
- What is the difference between arguments and parameters in Python?
- What is the difference between global and local variables in Python?
- What is the difference between single and double quotes in python?
- What is the difference between root.destroy() and root.quit() in Tkinter(Python)?
- What is the difference between Python functions datetime.now() and datetime.today()?
- What is the difference between a python module and a python package?
- What is difference between builtin and globals namespaces in Python?
- What is difference between raw_input() and input() functions in Python?
