teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

変数名編集

2018/10/12 13:53

投稿

thinkn1108
thinkn1108

スコア45

answer CHANGED
@@ -1,4 +1,5 @@
1
1
  これで動きますか?
2
+ (追記)変数間違っていたので変更しました
2
3
 
3
4
  ```
4
5
  import csv
@@ -8,9 +9,9 @@
8
9
  f = open('C:\Users\ho\py\log\log-181010.txt')
9
10
 
10
11
  for line in f:
11
- cookie = re.search(r'(?<=cookie=)[^&]*', col)
12
+ cookie = re.search(r'(?<=cookie=)[^&]*', line)
12
- prod = re.search(r'(?<=prod=)[^&]*', col)
13
+ prod = re.search(r'(?<=prod=)[^&]*', line)
13
14
  if cookie and prod:
14
15
  with open("output.csv", "a",newline='') as file:
15
- print("{},{}".format(cookie, prod), file=file)
16
+ print("{},{}".format(cookie.group(0), prod.group(0)), file=file)
16
17
  ```