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
#! python3 | |
#tsファイルをつなぎ合わせてひとつのmp4にする | |
import os | |
import subprocess | |
tmp_list = [i for i in os.listdir() if i.endswith('.ts')] | |
tmp_list.sort() | |
with open('./ts_list.txt', 'w') as ts_list: | |
for l in tmp_list: | |
ts_list.write(f'file {l}\n') | |
subprocess.run('/usr/local/bin/ffmpeg -f concat -safe 0 -i ts_list.txt -c copy output.mp4', shell=True) |
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))] |
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
import os , random , re , shutil | |
extention_list = ['.txt' , '.docx' , '.jpg'] | |
project_path = './chapter09/project01' | |
os.makedirs(project_path, exist_ok=True) | |
for i in range(100): | |
yyyy = random.randint(1972,2020) | |
mm = random.randint(1,12) | |
if mm < 10: | |
mm = str(0) + str(mm) | |
dd = random.randint(1,30) |
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
txtfile_list = [file_name for file_name in os.listdir() if re.search(r'.*.txt$', file_name)] |
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
# sample.txtの名刺や形容詞を置き換えて、表示して、sample2.txtに保存 | |
import re | |
# sample.txtの中身を読み込む | |
sample_file = open('./sample.txt') | |
sample_txt = sample_file.read() | |
# パターンマッチを定義する | |
word_regex = re.compile(r'ADJECTIVE|NOUN|VERB') |
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
#! python3 | |
# randomQuizGenerator.py - ランダム順に問題と答えを並べ問題集と解答集を作る | |
import random | |
import csv | |
# 都道府県の辞書を作る keyが都道府県 valuesが県庁所在地 | |
todoufuken_dict = {} | |
todoufuken_origin = open('./todoufuken.txt') # 同じフォルダ内に都道府県+県庁所在地のcsvがある前提。どこかから適当にDLしてちょっと整形 | |
todoufuken = csv.reader(todoufuken_origin) |
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
multilist = [[['a' for k in range(5)] for i in range(6)] for j in range(9)] |
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
import random | |
oknumber = random.randint(1,10) | |
n = 1 | |
print('1から10までの数を当ててください') | |
while oknumber != inputnumber: | |
inputnumber = int(input('数を入力してください:')) | |
if oknumber > inputnumber: |
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
#空文字はFalseだからnot空文字はTrue | |
name = '' | |
while not name: | |
print('名前を入力してください: ') | |
name = input() | |
print('OK') | |
#0はFalseだから0以外はTrue | |
print('同伴者は何人ですか?') | |
num_of_guests = int(input()) |
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
#ダメな例 | |
h = 0 | |
i = str(0) | |
j = 11 | |
while j != 10: | |
number = float(str(10.5) + (i * h) + str(1)) | |
rounding = round(number) | |
print(str(number) + ' is ' + str(rounding)) | |
h += 1 |