How to get file size in Python?

How to get a file's size in Python from the full path of a file?

asked Oct 15, 2015 by Eric Z Ma (44,280 points)

1 Answer

 
Best answer

You can use this piece of Python code:

os.path.getsize(file_path)

It returns the size in bytes. It raises os.error if the file does not exist or is inaccessible.

Manual of os.path.getsize(): https://docs.python.org/2/library/os.path.html#os.path.getsize

answered Oct 15, 2015 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...