Complete the code to check if a file is readable.
if os.access('example.txt', [1]): print('File is readable')
The os.R_OK flag checks if the file is readable.
Complete the code to open a file for writing only if it exists.
with open('data.txt', '[1]') as file: file.write('Hello')
The mode r+ opens the file for reading and writing but fails if the file does not exist.
Fix the error in the code to get the size of a file in bytes.
size = os.path.[1]('file.txt') print(size)
The correct function to get file size is os.path.getsize.
Fill both blanks to create a dictionary of file names and their sizes for files larger than 1000 bytes.
file_sizes = {f: os.path.[1](f) for f in files if os.path.[2](f) and os.path.getsize(f) > 1000}Use getsize to get file size and isfile to ensure the path is a file.
Fill all three blanks to filter files by extension and size, then create a dictionary with uppercase file names and their sizes.
filtered = {f.[1](): os.path.[2](f) for f in files if f.[3]('.txt') and os.path.getsize(f) > 500}Use upper() to convert file names, getsize to get file size, and endswith to filter by '.txt' extension.