Python reads all documents under a file

Source: Internet
Author: User

Two types of documents are stored under two paths, assuming there are 25 documents for each class of document

Def spamtest ():
DocList = []
Classlist = []
fulltext = []
For I in Range (1,26): #循环读取所有的txt, and resolves to a list
Wordlist = textparse (open (' path. txt '% i). Read ())
Doclist.append (wordlist)
Fulltext.extend (wordlist)
Classlist.append (1) #文档类别
Wordlist = textparse (open (path. txt '% i). Read ())
Doclist.append (wordlist) #将添加的列表作为一个元素添加到原列表中
Fulltext.extend (wordlist) #将添加的列表的中的元素对应添加到元列表中
Classlist.append (0) #文档类别

Python reads all documents under a file

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.