How do I get the weight of a file with python?

4

I would like to know how you can get the size of a ".txt" file in Python, for example in bytes. I have been looking on the Internet and I can not find any method that is useful for this.

Thank you very much.

    
asked by Pasblo 22.01.2018 в 20:55
source

1 answer

6

Try using import os :

import os
sizefile = os.stat('archivo.txt').st_size
print(sizefile)

or

sizefile = os.path.getsize('C:\user\folder\archivo.txt')
print(sizefile)

Note: with the stat method you can get multiple system characteristics of a file. You can see a little more detail in the documentation .

    
answered by 22.01.2018 / 21:53
source