xyzio

Generating a file filled with random characters in Python

leave a comment »

Generating a file filled with random characters in Python and printing out the elapsed time.

Output goes in tempOut.txt

#!/usr/bin/python

import random
import string
import time

start = time.time()

f = open('tempOut.txt', 'w')

for i in range(0,100000):
    line = ''
    for j in range(0,5000):
        line += str(random.choice(string.letters))

    f.write(line + "n")
    line = ''


f.close()

end = time.time()

print "Elapsed: " + str(end - start)

Written by M Kapoor

September 24, 2014 at 4:58 pm

Posted in python

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: