Python Program to Get the Size of a File

In this example, we will write a python program to get the size of the file. To better understand this example, make sure you have knowledge of the following tutorials:-

Python Program to Get the Size of a File

Let us assume we have an about.txt file in our current working directory.

The code for the program is:-
import os
def file_size(fname):
    info = os.stat(fname)
    return info.st_size


print("File size: %s bytes" % file_size("about.txt"))

The output of the above program is:-

File size: 293 bytes

SHARE Python Program to Get the Size of a File

You may also like...

Leave a Reply

Your email address will not be published.

Share