How the size of a file is calculated using python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How the size of a file is calculated using python?

Doubt

24th Sep 2020, 1:32 PM
Ved Tiwari
3 Answers
+ 9
ok - would be interesting to see how your logic does work. Can you share your knowledge with us? What are your doubts on using os methods? otherwise it can be done like this: You can use os module: import os f_size = os.path.getsize(my_path) make sure that the file path "my_path" is written correctly according to the operating system you are working with. "my_path" has to contain the path and the file name, separated with the separators according to the operating system you are using. It is recommended to do the handling of path information by using module pathlib.
24th Sep 2020, 1:50 PM
Lothar
Lothar - avatar
+ 3
You can use "os path" module or stat function.
24th Sep 2020, 1:38 PM
ADITYA KHANDELWAL
ADITYA KHANDELWAL - avatar
0
I don't want to use function i want to make it by logic
24th Sep 2020, 1:40 PM
Ved Tiwari