File size with os.path.getsize()

EasyOS Module Programs · 29 of 49

Write a Python program to get the size of a file in bytes.

Advertisement
Output
1000 bytes

Approach

  1. os.path.getsize().

Solution

Python
import os with open("size.bin", "wb") as f:    f.write(b"0123456789" * 100)print(os.path.getsize("size.bin"), "bytes")
Output
1000 bytes

Learn the concept

New to this topic? Read the lesson, then come back.

More os module programs

← All 49 OS Module Programs

Leave a Comment