open()
Built-in FunctionPython 2.0+Beginner
Opens a file and returns a file object for reading or writing
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
Learn by Difficulty
Quick Example
python
# open() creates a file object # with open("file.txt", "w") as f: # f.write("Hello!") print("open() is used for file I/O operations")
open() is a built-in function that opens a file and returns a file object for reading or writing.
Try in PlaygroundTags
builtinfunctioncorefile-iocontext-manager
Related Items
with
Keyword
Wraps a block with a context manager for automatic setup/teardown
pathlib
Stdlib — OS/File
Object-oriented filesystem paths (modern replacement for os.path)
io
Stdlib — OS/File
Core I/O tools: StringIO, BytesIO, and file I/O class hierarchy
os
Stdlib — OS/File
Interface to the OS: env vars, process management, file operations
shutil
Stdlib — OS/File
High-level file operations: copy, move, remove trees, archives