Re: hello, I want to change n bytes of a binary file

2005-11-02 Thread Ganesan Rajagopal
> "Fredrik" == Fredrik Lundh <[EMAIL PROTECTED]> writes: > if you want to XOR the bytes, you can do something like: > import array > b = array.array("B", a) > for i in range(len(b)): > b[i] = b[i] ^ 255 > b = b.tostring() > or > b = "".join([chr(ord(c) ^ 255) for

Re: hello, I want to change n bytes of a binary file

2005-11-02 Thread could ildg
Thanks to Fredrik Lundh,It works~On 11/2/05, Fredrik Lundh <[EMAIL PROTECTED] > wrote:"could ildg" wrote:> > so how can I do the binary stuff? >> 8-bit strings contain bytes.>> > I want a encrypt function like below:> > def encrypt(filename,n):>> f = open(filename,"rb+")>> > a=f.read (n)>> b = encr

Re: hello, I want to change n bytes of a binary file

2005-11-01 Thread Fredrik Lundh
"could ildg" wrote: > > so how can I do the binary stuff? > > 8-bit strings contain bytes. > > > I want a encrypt function like below: > > def encrypt(filename,n): > > f = open(filename,"rb+") > > > a=f.read(n) > > b = encrypt(a) Thank you~~,but where is the encrypt defined? oh, I though

Re: hello, I want to change n bytes of a binary file

2005-11-01 Thread Gerrit Holl
could ildg wrote: > > b = encrypt(a) > > Thank you~~,but where is the encrypt defined? > I suppose it's left as an exercise for the reader. Gerrit. -- Temperature in Kiruna, Lappland, Sweden: Tue Nov 1 15:35:25 2005 [UT] 2.6°C -- http://mail.python.org/mailman/listi

Re: hello, I want to change n bytes of a binary file

2005-11-01 Thread could ildg
On 11/1/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote: "could ildg" wrote:> I want to encrypt a very large birany file,> but if to change the whole file, it will take very long time,> so I just want to change n(n is an int) bytes of the file. > but when I turned to the file I/O of python, I found tha

Re: hello, I want to change n bytes of a binary file

2005-11-01 Thread Fredrik Lundh
"could ildg" wrote: > I want to encrypt a very large birany file, > but if to change the whole file, it will take very long time, > so I just want to change n(n is an int) bytes of the file. > but when I turned to the file I/O of python, I found that file object can > only read and write strings,

hello, I want to change n bytes of a binary file

2005-11-01 Thread could ildg
I want to encrypt a very large birany file,but if to change the whole file, it will take very long time,so I just want to change n(n is an int) bytes of the file.but when I turned to the file I/O of python, I found that file object can only read and write strings, so how can I do the binary stuff?I