OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.
os.truncate() method truncates the file corresponding to path so that it is at most length bytes in size. This function can support file descriptor too.
Syntax: os.truncate(path, length)
path: This parameter is the path or file descriptor of the file that is to be truncated.
length: This is the length of the file upto which file is to be truncated.
Return Value: This method does not returns any value.
Example #1 :
os.truncate() method to truncate a file using it’s path.
Example #2 :
os.truncate() method to truncate a file using a file descriptor
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course