[Tutor] Creating Binary Files of 1MB

Becky Mcquilling ladymcse2000 at gmail.com
Sun Apr 17 19:39:13 CEST 2011


Thanks, Steve.  For the first step, I just wasn't sure how to write the
file.

I appreciate the help.

Becky

On Sun, Apr 17, 2011 at 12:34 AM, Steven D'Aprano <steve at pearwood.info>wrote:

> Becky Mcquilling wrote:
>
>> I'm trying to work out a method to create a binary file of 1mb and I'm
>> somewhat confused by the docs I'm reading is there a method that will do
>> this?
>>
>
>
> # Open a file in binary (b) mode for writing.
> fp = open("mybinaryfile", "wb")
> # Write whatever data you like to it.
> fp.write('\0'*1000000)
> fp.close()
>
>
> That writes one million ASCII NULL bytes to the file. If you prefer binary
> megabytes instead of decimal megabytes, use 1024*1024 instead of one
> million.
>
> If you want some other binary data, you'll have to tell us what binary data
> you want to write.
>
>
>
> --
> Steven
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110417/89bd27d3/attachment.html>


More information about the Tutor mailing list