次のコードを解決するために誰かが私を助けることができるかどうか疑問に思っています:
次の内容の report.txt というテキスト ファイルがあります (すべて同じ行です)。
Printed: 2013-07-12 05:09 PM QC Product: PROT2 CON Level: Level 3 Priority: QC Method RF Result 174 IU/mL Lot Number: 3BQH01 Sample ID: 3BQH01 Instrument ID: DV330681 QC Range 158.0 - 236.0 Comment Completed: 2013-07-12 17:09:14 Comment: Trigger: Manual Trigger Operator C160487AUR Time of Run 2013-07-12 17:09:14 Reagent 13049MA
次の情報を取得する必要があります( : の後の値のみ)
QC Product: PROT2 CON
Level: Level 3
Sample ID: 3BQH01
私は次のコードを試していました:
with open ('report.txt', 'r') as inF:
for line in inF:
if 'Sample ID:' in line:
SID = line.split(':')[1].strip()
if 'Level:' in line:
LEV = line.split(':')[1].strip()
if 'QC Product:' in line:
QCP = line.split(':')[1].strip()
誰かがアイデアや他の解決策を持っていますか?
皆様のご尽力とご支援に心より感謝申し上げます。
コーエンをよろしく