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")
-
6:10:21
JdaDelete
1 day ago $3.66 earnedDino Crisis - Sega Saturday
66K4 -
23:22
MYLUNCHBREAK CHANNEL PAGE
1 day agoUnder The Necropolis - Pt 5
67.4K28 -
2:26:11
Jewels Jones Live ®
2 days agoWINNING BIGLY | A Political Rendezvous - Ep. 108
132K44 -
2:04:49
Bare Knuckle Fighting Championship
4 days agoBKFC FIGHT NIGHT MOHEGAN SUN FREE FIGHTS
63.1K7 -
25:09
BlackDiamondGunsandGear
9 hours agoYou NEED to be Training For Whats to Come
43.9K11 -
20:03
Sideserf Cake Studio
15 hours ago $1.64 earnedA HUNGRY HUNGRY HIPPOS CAKE THAT ACTUALLY WORKS?
42.4K13 -
23:51
marcushouse
16 hours ago $1.38 earnedStarship’s Next Move Is Coming Sooner Than You Think!
30K6 -
22:24
The Finance Hub
22 hours ago $9.32 earnedBREAKING: JOE ROGAN JUST DROPPED A MASSIVE BOMBSHELL!!!
32.9K32 -
55:02
PMG
12 hours ago $0.82 earnedHannah Faulkner and Miriam Shaw | Moms on A Mission
22.8K1 -
1:21:05
I_Came_With_Fire_Podcast
23 hours ago"Veteran Health, Military Culture, and American Exceptionalism" with Matt Kenney
92.4K21