find the size of a file in python

To find the size of a file in Python, you can use the os module's path.getsize() function. The getsize() function returns the size of the file in bytes.

Here's the code for finding the size of a file using the getsize() function:

main.py
import os

file_path = 'path/to/your/file'
file_size = os.path.getsize(file_path)

print("File size in bytes is :", file_size)
127 chars
7 lines

In this code, replace path/to/your/file with the actual path of the file you want to find the size of. The getsize() function will return the size of the file in bytes, which is then printed to the console using the print() function.

gistlibby LogSnag