On this page
genericpath.getsize
Prev: genericpath.getmtime | Up: genericpath | Next: genericpath.isdevdrive
Rel: genericpath.commonprefix, genericpath.exists, genericpath.getatime, genericpath.getctime
Ref: docs.python.org — genericpath.getsize
Tags: #public #python3 #stdlib #genericpath
Import
import genericpath
from genericpath import getsize
Signature & Overview
genericpath.getsize(filename)
Return the size of a file, reported by os.stat().
Usage
import os
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as tmp:
p = Path(tmp) / "f.bin"
p.write_bytes(b"1234")
assert os.path.getsize(p) == 4
Gotchas
- Size in bytes: Raises
FileNotFoundErrorif the path doesn't exist.
REPL Inspect
from genericpath import getsize
help(getsize)
Linked from
Related notes
- tuts/python3/stdlib_module/genericpath/getmtime Linked here; links to this page; shared tags: #genericpath, #stdlib
- tuts/python3/stdlib_module/genericpath/isdevdrive Linked here; links to this page; shared tags: #genericpath, #stdlib
- tuts/python3/stdlib_module/genericpath Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/genericpath/commonprefix Linked here; shared tags: #genericpath, #stdlib
- tuts/python3/stdlib_module/genericpath/exists Linked here; shared tags: #genericpath, #stdlib
- tuts/python3/stdlib_module/genericpath/getatime Linked here; shared tags: #genericpath, #stdlib
- tuts/python3/stdlib_module/genericpath/getctime Linked here; shared tags: #genericpath, #stdlib
- tuts/python3/stdlib_module/genericpath/isdir shared tags: #genericpath, #stdlib
- tuts/python3/stdlib_module/genericpath/isfile shared tags: #genericpath, #stdlib
- tuts/python3/stdlib_module/genericpath/isjunction shared tags: #genericpath, #stdlib