Simple use of Python to automatically generate articles,

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.