On 4/3/2012 7:54 AM Khalid Al-Ghamdi said...
Hi,
The following code tries to generate some dummy data for regex
exercises. My question is in reference the line before last:
dom="".join(choice(lc) for j in range (dlen))
how does the interpreter know what "j" is supposed to refer to when it
was not mentioned prior?
Prior value or not, j is the loop variable that steps over range(dlen)
and refers to the numbers 0 to dlen-1 in turn.
Did you mean to ask something about the code below as well?
Emile
from random import randrange, choice
from string import ascii_lowercase as lc
from sys import maxsize
from time import ctime
tlds = ('com', 'edu', 'net', 'org', 'gov')
for i in range(randrange(5,11)):
dtint=randrange(maxsize) #pick a random number to use to
generate random date in next line
dtstr=ctime(dtint) #date string
llen=randrange(4,8) #login is shorter
login=''.join(choice(lc) for j in range(llen))
dlen=randrange(llen,13) #domain is longer
dom="".join(choice(lc) for j in range (dlen))
print('{}::{}@{}.{}::{}-{}-{}'.format(dtstr,login,dom,choice(tlds),dtint,llen,dlen))
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor