-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_text.py
More file actions
42 lines (33 loc) · 1.04 KB
/
create_text.py
File metadata and controls
42 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
######################################################
content = '''
loguru>=0.7.0
PyYAML>=5.3.1
gdown>=4.7.1
GitPython>=3.1.0
filterpy>=1.4.5
'''
file_path = 'requirements.txt'
with open(file_path, 'w') as file:
file.write(content)
######################################################
content = '''
This is line 1.
This is line 2.
This is line 3.
'''
file_path = 'example.txt'
with open(file_path, 'w') as file:
file.write(content)
######################################################
def write_list_to_file(lst, filename):
# ファイルを書き込みモードで開く
with open(filename, 'w') as file:
# リストの要素をスペース区切りで書き込む
file.write(' '.join(str(item) for item in lst))
# テスト用のリスト
my_list = [1, 2, 3, 4, 5]
# ファイル名として使用する文字列
file_name = "output.txt"
# リストをファイルに書き込む
write_list_to_file(my_list, file_name)
######################################################