Premium Only Content

Working with Dates and Times |Section 6|Celestial Warrior
Here is a tricky exercise.
1.Please download thethree text files attached in this lecture and put them in a folder. The first text file contains the textContent1.The second contains Content2and the third Content3.
2. You should create a Python script that generates a new text file which should contain the content of all three text files. So the generated file should have this content:
Content1
Content2
Content3
In other words, your Pythonscript should merge the three text files.
3. Also, the name of the output file should be the current timestamp. Example:2017-11-01-13-57-39-170965.txt
You have some tips in the next lecture and the solution in the lecture afterthat.
1. Consider using the glob2 third-party library to generate a list of filenames to iterate through.
2. Use a "with" statement to create a new text file and then iterate through the file list inside that "with"statement and open andread existing file contentsin each iterationand write them to new text file.
import glob2
import datetime
filenames=glob2.glob("*.txt")
with open(datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S-%f")+".txt", 'w') as file:
for filename in filenames:
with open(filename,"r") as f:
file.write(f.read()+"\n")
-
LIVE
Major League Fishing
5 days agoLIVE! - Fishing Clash Team Series: Heritage Cup - Day 2
461 watching -
DVR
Simply Bitcoin
2 hours ago $0.21 earnedNEW REPORT SUGGESTS THE BITCOIN SUPPLY SHOCK IS ACCELERATING?! | EP 1332
280 -
10:31
Dr. Eric Berg
3 hours ago13 Foods You Should Never Buy Organic
27.4K15 -
15:10
SB Mowing
1 month agoShe had TEARS OF JOY on her face - An update on Beth
18.6K31 -
LIVE
Lofi Girl
3 years agolofi hip hop radio 📚 - beats to relax/study to
230 watching -
2:15:26
Nikko Ortiz
3 hours agoLIVE - Farm Animals Attack!
169K7 -
9:30
Sugar Spun Run
6 hours ago $0.86 earnedBlack and White Cookies
83.6K1 -
2:45
SLS - Street League Skateboarding
4 days agoManny Santiago's 'THIS IS 40' Part
47.3K2 -
6:40
Homesteading Family
5 days agoNever Make Pie Crust From Scratch Again (Do THIS Instead)
39K5 -
44:20
Melissa K Norris
3 days ago $0.72 earnedThe Most Overlooked Way to Preserve Food for Months (No Freezer Needed) w/ Sam Knapp
28.2K1