Python Forum
Get amount of bytes in a file - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Get amount of bytes in a file (/thread-34702.html)



Get amount of bytes in a file - chesschaser - Aug-23-2021

Hi guys!

I am writing a program and it has a variable in it of type bytes. i need to get the amount of bytes this variable contains.
Any help will be appreciated.

Thanks! Smile


RE: Get amount of bytes in a file - deanhystad - Aug-23-2021

The same way you get the number of items in any collection; len(collection).
x = b'123456789'
print(len(x))
Output:
9