- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create file of particular size in Python?
To create a file of a particular size, just seek to the byte number(size) you want to create the file of and write a byte there.
with open('my_file', 'wb') as f: f.seek(1024 * 1024 * 1024) # One GB f.write('0')
This creates a sparse file by not actually taking up all that space. To create a full file, you should write the whole file:
with open('my_file', 'wb') as f: num_chars = 1024 * 1024 * 1024 f.write('0' * num_chars)
- How to create a dummy file of any size with PowerShell?
- How to create a duplicate file of an existing file using Python?
- How to create hardlink of a file using Python?
- How to create softlink of a file using Python?
- How to create an empty file using Python?
- How to create a tar file using Python?
- How to create a zip file using Python?
- Python program to randomly create N Lists of K size
- C Program to find size of a File
- How to create a Python dictionary from text file?
- How to shrink or extend the size of a file in Linux?
- Validate the size of input=file in HTML5?
- How to create a unique temporary file name using Python?
- How to create Python objects based on an XML file?
- How to create a JAR file?