Table of Contents
In this example, you will learn to check the file size.
To understand this example, you should have the knowledge of the following Python programming topics:
1. Example 1: Using os module
import os file_stat = os.stat('my_file.txt') print(file_stat.st_size)
Output
34
Using stat()
from the os
module, you can get the details of a file. Use the st_size
attribute of stat()
method to get the file size.
The unit of the file size is byte
.
2. Example 2: Using pathlib module
from pathlib import Path file = Path('my_file.txt') print(file.stat().st_size)
Output
34
Using the pathlib
module, you can do the same thing as shown above. The unit of the file size is byte
.
Related posts:
Python String title()
Python Object Oriented Programming
Python staticmethod()
Python String find()
Python datetime
Python String isspace()
Python String isidentifier()
Python String center()
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Data Types
Python Program to Create Pyramid Patterns
Python Deep Learning Cookbook - Indra den Bakker
Python Program to Sort Words in Alphabetic Order
Python Set union()
Python complex()
Python locals()
Python String format_map()
Python Matrices and NumPy Arrays
Python Operators
Python Program to Iterate Through Two Lists in Parallel
Python Program to Check Whether a String is Palindrome or Not
Python slice()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python Set issuperset()
Python type()
Python Program to Catch Multiple Exceptions in One Line
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python abs()
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python Package
Python String count()