Python Practice › OS Module Programs › Program 29
File size with os.path.getsize()
Write a Python program to get the size of a file in bytes.
Output
1000 bytes
Approach
os.path.getsize().
Solution
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.