My question is: why write(''.join(...)) works slowly than
writelines(...)? Here's the code:

import sys
import random

#try:
    #import psyco
    #psyco.full()
#except ImportError:
    #pass


def encrypt(key, infile, outfile, bufsize=65536):
    random.seed(key)
    in_buf = infile.read(bufsize)
    while in_buf:
        outfile.write(''.join(chr(ord(char) ^ random.randint(0, 255))
for char in in_buf))
        in_buf = infile.read(bufsize)


if __name__ == '__main__':
    import time
    key = int(sys.argv[1])
    infile = open(sys.argv[2], 'rb')
    outfile = open(sys.argv[3], 'wb')
    t = time.time()
    encrypt(key, infile, outfile)
    print time.time() - t

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to