看板 Python 關於我們 聯絡資訊
請問一下兩個問題: 1。 正規表示法我用c = re.compile("module ([^\(]+) (") 他會report error message如下 Traceback (most recent call last): File "removmodule", line 26, in <module> BuiltNetlist(NETLIST_FILE_NAME) File "removmodule", line 7, in BuiltNetlist c = re.compile("module ([^\(]+) (") File "/cad/Python-2.5.1/Lib/re.py", line 180, in compile return _compile(pattern, flags) File "/cad/Python-2.5.1/Lib/re.py", line 233, in _compile raise error, v # invalid expression sre_constants.error: unbalanced parenthesis 2。 findall(text) 裡面的text是開檔的point name嗎? ※ 引述《Lucemia (生の直感、死の予感)》之銘言: : like this? : import re : c = re.compile("module ([^\(]+) (") : module_name = set([k.strip() for k in c.findall(text)]) : ※ 引述《jeffreychen ()》之銘言: : : 想請問一下各位大大一個問題: : : 例子: : : 我有一個verilog file,想把所有的module_name 收集起來: : : module AAA ( : : . : : . : : . : : ); : : . : : . : : . : : endmodule : : AAA 是module_name 想請問各位大大要如何取得 AAA這個modue_name 的寫法比較好呢 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.128.190.162
Lucemia:c = re.compile("module ([^\(]+) (") 改成這樣 01/08 22:49