import os from PyQt5.QtCore import QFileInfo file_path = 'path/to/my/file.txt' if os.path.isfile(file_path): file_info = QFileInfo(file_path) print('File size:', file_info.size()) else: print('File not found')
from PyQt5.QtCore import QFileInfo file_path = 'path/to/my/file.txt' file_info = QFileInfo(file_path) print('File extension:', file_info.suffix())In this example, we create a `QFileInfo` object and use the `suffix` method to obtain the file extension. Both of the above examples use the PyQt5 package library.