如何在Python中从文本中获取特定单词?

2024-09-21 04:28:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一条短信,实际上是一封电子邮件,来自我的大学,像这样:

FEDERAL UNIVERSITY OF ABC

Name : Rodrigo Martins de Oliveira
RA: 11009713
Campus : Campus Santo André
Shift: Morning

weekly charge
=============
Credit (T-P) : 18
Load - time (T-P-I) : 44

Requested enrollment in the following classes :
=================================
  BC0208 - Mechanical Phenomenons A2-Morning (Santo André) - TPI (3-2-6) - Campus St. André
  Tuesday from 10:00 to 12:00
  Tuesday from 08:00 to 10:00
  Thursday from 08:00 to 10:00
  BC0504 - The Nature of Information A2-Morning (Santo André) - TPI (3-0-4) - Campus St. André
  Friday from 08:00 to 10:00
  Thursday from 10:00 to 12:00
  BC0306 - Transformations in Living Beings and Environment A1-Morning (Santo André) - TPI (3-0-4) - Campus St. André
  Wednesday from 08:00 to 10:00
  Monday from 10:00 to 12:00
  BC0402 - One Variable Functions A1-Morning (Santo André) - TPI (4-0-6) - Campus St. André
  Monday from 08:00 to 10:00
  Wednesday from 10:00 to 12:00
  BC0404 - Analytic Geometry A2-Morning (Santo André) - TPI (3-0-6) - Campus St. André
  Wednesday from 08:00 to 10:00
  Friday from 10:00 to 12:00


Code of authenticity : 4TlG58kWtrdN1caEJM02Ik8/C01p + qLeSFDOtXHZLMJrafv3H/soML2XPkrU pBHmBXBwMgRbd7Y =



Note : Document for simple conference, follow in the site the results of this enrollment request.

-
This email was sent automatically on Thursday, September 19, 2013 , 12:06 . Please do not reply .
If there are any technical questions , please contact via email xxxxxx@yyyyy.zzz

这封电子邮件给了我我所申请的课程和他们各自的时间表。我正在编写一个程序来自动获取这些信息,并创建一个如下表: Timetable

我刚刚开始编写这个程序,我需要获得类(BC****)的代码和它们各自的时间表,以便我绘制表。在

我该怎么做?在


Tags: ofthetoinfroma2stmorning
1条回答
网友
1楼 · 发布于 2024-09-21 04:28:28

根据一条新的线拆分线,尽管这看起来是awk的工作!!但在python中

lst = text.split("\n")
#lst is of type list
for line in lst:
    if lst[:2] == "BC":
        #tadah, you know this line contains what you want do some magic

一个警告,可能是在BC部分前面有一些空格,所以把多余的空格撕掉

相关问题 更多 >

    热门问题