Skip to content

Instantly share code, notes, and snippets.

@naoyeye
Last active August 29, 2015 14:25
Show Gist options
  • Save naoyeye/1d464c14eb90087b3a60 to your computer and use it in GitHub Desktop.
Save naoyeye/1d464c14eb90087b3a60 to your computer and use it in GitHub Desktop.
生成随机字符串并保存到 txt 文件中
#!/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