2013-10-20 205 views
-1

我有一個文本,實際上是一個電子郵件,從我的大學是這樣的:如何從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 [email protected] 

此郵件給我,我要求入學的種類和它們各自的時間表。我書面方式一個程序來自動獲取這些信息並做出一個表像這樣的: Timetable

我剛開始寫這個程序,我需要的類(BC****)及其各自的日程安排的代碼我畫陰謀。

我該怎麼辦?

+0

你知道些什麼關於Python? – wwii

+0

我開始學習Python,我認爲制定時間表程序應該是一個好的開始。 –

+1

如果您開始閱讀Python文檔中的教程並牢記您的問題,我相信您會得到很多想法。一旦你開始,如果你陷入困境,發佈你有什麼和錯誤。不要試圖一下子做所有事情 - 看@雅各布的答案,看看你能否弄清楚它是如何工作的。 – wwii

回答

1

根據新行分割行,雖然這看起來像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部分,所以撕多餘的空間了

+0

謝謝,我明白了! –

+0

太棒了!很高興聽到 –

相關問題