-
Notifications
You must be signed in to change notification settings - Fork 0
/
combine_files.py
27 lines (20 loc) · 1.06 KB
/
combine_files.py
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
import glob2
#######################################################################
# find all file names with a .txt extension
filenames = glob2.glob('data/political_news/fake_headlines/*.txt')
# concatenate all individual files into one file
with open("fake_headlines.txt", "w", encoding="ISO-8859-1") as f:
for file in filenames:
with open(file, encoding="ISO-8859-1") as infile:
# append 'fake' parameter at end of each line
f.write(infile.read()+"\t"+"fake"+"\n")
########################################################################
# find all file names with a .txt extension
filenames = glob2.glob('data/political_news/real_headlines/*.txt')
# concatenate all individual files into one file
with open("real_headlines.txt", "w", encoding="ISO-8859-1") as f:
for file in filenames:
with open(file, encoding="ISO-8859-1") as infile:
# append 'fake' parameter at end of each line
f.write(infile.read()+"\t"+"real"+"\n")
########################################################################