0

次のコードは、スクリプトの先頭で「line」変数を宣言すると、期待どおりに機能します。何かのようなもの ...

s = "Jul 15 12:12:51 whitelist logger: 1|999999999999|id:d9faff7c-4016-4343-b494-37028763bb66 submit date:1307130919 done date:1307130919 stat:DELIVRD err:0|L_VB3_NM_K_P|1373687445|vivnel2|L_VB3_GH_K_P|promo_camp1-bd153424349bc647|1"

ファイルを開いて行をループすると、groups 属性が機能しません。エラーが表示されます:AttributeError: 'NoneType' オブジェクトには属性 'groups' がありません

# cat mylast.py
import re

f = open('customer.csv')

for line in f:

      logger_re = re.compile(
     "logger: ([^ ]+)\
      submit date:(\d+)\
      done date:(\d+)\
      stat:(.+)\
      err:(.+)$")
      myvalues = logger_re.search(line).groups()
      print myvalues

f.close()

例外:

# python mylast.py
Traceback (most recent call last):
  File "mylast.py", line 13, in ?
    myvalues = logger_re.search(line).groups()
AttributeError: 'NoneType' object has no attribute 'groups'
4

2 に答える 2