About 3,610,000 results
Open links in new tab
  1. File Objects in Python - GeeksforGeeks

    Apr 3, 2017 · Attributes: closed: returns a boolean indicating the current state of the file object. It returns true if the file is closed and false when the file is open. encoding: The encoding that this file uses. When Unicode strings are written to a file, they will be converted to byte strings using this encoding. mode: The I/O mode for the file. If the ...

  2. python - How to read file attributes in a directory ... - Stack Overflow

    Apr 26, 2021 · When looking for file attributes for all files in a directory, and you are using Python 3.5 or newer, use the os.scandir() function to get a directory listing with file attributes combined. This can potentially be more efficient than using os.listdir() and then retrieve the …

  3. How to Retrieve and Set File Metadata and Attributes in Python

    File attributes control how files behave and how they can be accessed. Python allows you to retrieve and set attributes such as read-only and hidden status using the os and stat modules. Retrieving File Attributes. To retrieve file attributes, use the os.stat() function and constants from the stat module. The example code below checks the read ...

  4. Working With Files in Python

    Oct 4, 2018 · Getting File Attributes. Python makes retrieving file attributes such as file size and modified times easy. This is done through os.stat(), os.scandir(), or pathlib.Path(). os.scandir() and pathlib.Path() retrieve a directory listing with file attributes combined.

  5. Files in python, File Built-in Function, File Built-in Attributes ...

    File Built-in Attributes. Python Supports following built-in attributes, those are. file.name - returns the name of the file which is already opened. file.mode - returns the access mode of opened file. file.closed - returns true, if the file closed, otherwise false.

  6. Get file attributes (hidden, readonly, system, archive) in Python

    Nov 29, 2014 · Since Python 3.5, os.stat(), os.fstat() and os.lstat() returns a class os.stat_result that, on Windows systems, includes st_file_attributes. You can use the FILE_ATTRIBUTE_* constants in the stat module to check the file attributes.

  7. File Handling in Python - GeeksforGeeks

    Jan 14, 2025 · To open a file we can use open() function, which requires file path and mode as arguments: This code opens file named geeks.txt. When opening a file, we must specify the mode we want to which specifies what we want to do with the file. Here’s a table of the different modes available: Read-only mode. Opens the file for reading.

  8. Python add custom property/metadata to file - Stack Overflow

    Dec 16, 2016 · In Python, is it possible to add custom property/metadata to a file? For example, I need to add "FileInfo" as a new property of the file. I need a method that works on various file formats. When you say "to a file", are you referring to the Python file object or to the file itself ? Heads up: this answer only works on Linux.

  9. Mastering File Metadata and Attributes in Python: A …

    Python, with its rich set of libraries and straightforward syntax, provides a robust platform for managing file metadata and attributes. This guide delves into the nuances of acquiring and manipulating this data, presenting methods that cater to various needs and scenarios.

  10. File Objects in Python - PYnative

    Jul 3, 2021 · Learn file objects in Python. Use file object methods and attributes to perform various file operations.

Refresh