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

Fredrik Lundh fredrik at pythonware.com
Tue Nov 1 15:57:48 CET 2005

"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,
> 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)

f.seek(0) # rewind


More information about the Python-list mailing list