On this page
  1. os.DirEntry
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

os.DirEntry

Prev: os.cpu_count | Up: os | Next: os.dup
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.DirEntry
Tags: #public #python3 #stdlib #os


Import

import os
from os import DirEntry

Signature & Overview

os.DirEntry()

os.DirEntry class.

Methods & Attributes

Usage

import os
from pathlib import Path
import tempfile

with tempfile.TemporaryDirectory() as tmp:
    (Path(tmp) / "a.txt").write_text("hi", encoding="utf-8")
    with os.scandir(tmp) as it:
        entries = list(it)
    assert len(entries) == 1 and isinstance(entries[0], os.DirEntry)
    assert entries[0].name == "a.txt" and entries[0].is_file()

Gotchas

REPL Inspect

from os import DirEntry
help(DirEntry)

Linked from

Related notes