We are working on Python code in the window environment.
Depending on the size of the file, I'm working on a different code (such as writing an e-mail if it's over 100 kb) I can do everything else, but I don't know the function to find out the size of the file. Where can I find related functions?
python file size
os.stat(path) returns the stat structure for that path. For information on stat structure, see This answer
import os
mystat = os.stat("myfile.JSON") #
print("mystat :", mystat)
mysize = mystat.st_size
print("mysize :", mysize)
Result:
mystat : os.stat_result(st_mode=33188, st_ino=2465615, st_dev=16777220, st_nlink=1, st_uid=501, st_gid=20, st_size=211, st_atime=1452665170, st_mtime=1452665170, st_ctime=1452665170)
mysize : 211
import os
mysize = os.path.getsize("myfile.JSON")
print("mysize :", mysize)
Result: mysize: 211
© 2025 OneMinuteCode. All rights reserved.