Created
December 7, 2020 13:47
-
-
Save kotoripiyopiyo/c35257a3ece520b03e1802f28a2e00ad to your computer and use it in GitHub Desktop.
ランダムな文字列が入ってたり入ってなかったりする日付入りダミーファイルを大量生成する
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
# ランダムな日付や文字列が入ったファイルを大量生成する | |
# 実行すると、./chapter09/project01配下に、100個のファイルが生成される | |
extention_list = ['txt' , 'docx' , 'jpg'] | |
pj_path = './chapter09/project01' | |
os.makedirs(pj_path, exist_ok=True) | |
str_all = f'{string.digits}{string.ascii_letters}' | |
def random_all(str_num): | |
str_list = [random.choice(str_all) for i in range(random.randint(2,str_num))] | |
rd_str = ''.join(str_list) | |
rd_date = f'{random.randint(1,12)}-{random.randint(1,31)}-{random.randint(1972,2020)}' | |
rd_ext = extention_list[random.randint(0,2)] | |
rd_filename = [] | |
rd_filename.append(f'{pj_path}/{rd_str}{rd_date}.{rd_ext}') | |
rd_filename.append(f'{pj_path}/{rd_date}{rd_str}.{rd_ext}') | |
rd_filename.append(f'{pj_path}/{rd_str}.{rd_ext}') | |
rd_filename.append(f'{pj_path}/{rd_date}.{rd_ext}') | |
return rd_filename | |
for i in range(100): | |
rd_filenames = random_all(10) | |
filename = open(rd_filenames[random.randint(0,3)], 'w') | |
filename.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment