-2
텍스트 파일의 특정 부분을 추출하고 싶습니다. 내 입력 파일 :파일에서 특정 텍스트를 추출하는 방법은 무엇입니까?
-- num cell port function safe [ccell disval rslt]
"17 (BC_1, CLK, input, X)," &
"16 (BC_1, OC_NEG, input, X), " &-- Merged input/
" 8 (BC_1, D(8), input, X)," & -- cell 16 @ 1 -> Hi-Z
" 7 (BC_1, Q(1), output3, X, 16, 1, Z)," &
" 0 (BC_1, Q(8), output3, X, 16, 1, Z)";
와 나는 같은 수의 출력이 필요합니다
num cell port function safe ccell
17 BC_1 CLK input X
16 BC_1 OC_NEG input X
16 BC_1 * control 1
8 BC_1 D8 input X
7 BC_1 Q1 output3 X 16 1
0 BC_1 Q8 output3 X 16 1
지금까지 내가 코드를 아래에 시도했지만 인덱스 오류를했다. 조언 부탁드립니다.
import re
lines=open("input.txt",'r').readlines()
for line in lines:
a=re.findall(r'\w+',line)
print re.findall(r'\w+',line)
print a[0],a[1],a[2],a[3],a[4],a[5],a[6]
나는 다음과 같이 파이썬 2.6.6 및 오류를 사용하고 있습니다 :
['num', 'cell', 'port', 'function', 'safe', 'ccell', 'disval', 'rslt']
num cell port function safe ccell disval
['17', 'BC_1', 'CLK', 'input', 'X']
17 BC_1 CLK input X
Traceback (most recent call last):
File "C:\Users\ctee1\Desktop\pyparsing\outputparser.py", line 39, in <module>
print a[0],a[1],a[2],a[3],a[4],a[5],a[6]
IndexError: list index out of range
어떤 언어이 무엇입니까? 정확한 예외 메시지 사본을 얻을 수 있습니까? – Dessus
아마도 파이썬? –