Last active
August 29, 2015 14:25
-
-
Save naoyeye/1d464c14eb90087b3a60 to your computer and use it in GitHub Desktop.
生成随机字符串并保存到 txt 文件中
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import string, random | |
def RandomStringGenerator(size=12, chars=string.ascii_letters + string.digits): | |
return '\n {"expired": false, "coupon": "' + ''.join(random.choice(chars) for _ in range(size)) + '"}' | |
def save(filename, contents): | |
fh = open(filename, 'w') | |
fh.write(contents) | |
fh.close() | |
arr = [] | |
for num in range(0, 800): | |
arr.append(RandomStringGenerator()) | |
# print '{"results":[' + ','.join(arr) + ']}' | |
save('/Users/hanjiyun/Desktop/coupon.json', '{"results":[' + ','.join(arr) + '\n]}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment