Để tạo file dung lượng xác định, seek đến byte số (size) muốn tạo và ghi một byte.
Ví dụ
with open('my_file', 'wb') as f:
f.seek(1024 * 1024 * 1024) # 1 GB
f.write(b'0')
Tạo sparse file không chiếm dung lượng thật. Để tạo file đầy đủ, ghi toàn bộ:
with open('my_file', 'wb') as f:
num_chars = 1024 * 1024 * 1024
f.write(b'0' * num_chars)