Sometimes, we want to check file size in Python.
In this article, we’ll look at how to check file size in Python.
How to check file size in Python?
To check file size in Python, we can use the os.path.getsize
method.
For instance, we write:
import os
b = os.path.getsize("file.txt")
print(b)
We call os.path.getsize
with the file path of the file to get the size of.
Therefore b
is a number in bytes.
Conclusion
To check file size in Python, we can use the os.path.getsize
method.