Simple use of Python to automatically generate articles,
17 records are required to cope with certain situations. Although not important, 17 identical copies are not very good. The record is roughly divided into four sections. Therefore, we decided to provide four options for each segment, one for each segment, and splice them into four paragraphs to save them as a file. The file name is called "XX record + date ". Emergency creation, using the "File Operation" and "generate random number" functions. Relatively simple. Later extensions can be used with databases.
Copy codeThe Code is as follows:
#-*-Coding: cp936 -*-
Import random
Title = 'xxx weekly meeting \ n meeting time :'
Timelist = ['20140901', '20160301', '20160301', '20160301', '20160301', '20160301', '20160301', '20160301 ',
'Octoken ',
'Octoken ',
] # List containing 17 dates
Str1 = 'Meeting location: Room XXX \ N'
Str2 = 'host: James \ N'
Str3 = 'participants: AAA, BBB, ccc \ n meeting content: \ N'
List1 = ['first (a) \ n', 'First (B) \ n', 'First (C) \ n ', 'section 1 (Type D) \ n']
List2 = ['second (a) \ n', 'second (B) \ n', 'second (C) \ n ', 'Second paragraph (type D) \ n']
List3 = ['third (a) \ n', 'third (B) \ n', 'third (C) \ n ', 'Third (type D) \ n']
List4 = ['Fourth (a) \ n', 'Fourth (B) \ n', 'Fourth (C) \ n ', 'Fourth paragraph (type D) \ n']
For I in range (0, 17 ):
Aa = random. randint () # The value is randomly assigned to aa "0, 1, 2, 3 ".
Bb = random. randint (0, 3)
Cc = random. randint (0, 3)
Dd = random. randint (0, 3)
Print timelist [I]
Print aa, bb, cc, dd
F=open('xxxweekly meeting '{timelist} I }}'.txt ', 'w') # create a file named "title + date ". R read-only, w writable, a appended
F. write (title + timelist [I] + '\ n' + str1 + str2 + str3 + list1 [aa] + list2 [bb] + list3 [cc] + list4 [dd] + '\ n ')
# Write the first segment, second segment, third segment, and fourth segment randomly generated in the file.
F. close () # close file read/write.
Something for a party, ah, I am tianchao ..... Let's take a look at the ideas in this article. Others are not the ones we can consider currently.