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.
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.
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 .