[Tutor] Dict question
Nate Custer
gncuster@firehead.org
13 Jun 2001 18:28:04 -0500
--=-AGVnSkuT5LiNtNpkWBA5
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Hi all,
I am calling a dict (format should be {string: [list]} ). It fails as:
File "guardian_sum.py", line 45, in scan
l.append(error_ip)
AttributeError: 'string' object has no attribute 'append'
Why does the error_dict.get() return a string?
Thanks in advance,
Nate Custer
====================================Begin Code
==========================
error_dict = {}
def scan():
guardian = open("/var/log/guardian/guardian.log", 'r')
ipchains = open("/home/nsc/ipchains.log", 'w')
odd = open("/home/nsc/odd.log", 'w')
nums = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' ]
days = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
blocked_host = []
while 1:
# read the line
line = guardian.readline()
if not line: break
if line[:3] in days:
word = string.split (line)
for w in word:
if 'IDS' == w[:3]:
error = w
if w[0] in nums:
error_ip = w
if error_dict.has_key(error):
l = error_dict.get(error)
l.append(error_ip)
append = {error: l}
error_dict.update (append)
else:
x = [`error_ip`]
append = {error: x}
error_dict.update (append)
--=-AGVnSkuT5LiNtNpkWBA5
Content-Type: text/html; charset=utf-8
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/0.9.99.0">
</HEAD>
<BODY>Hi all,<br>
<br>
I am calling a dict (format should be {string: [list]} ). It fails as:<br>
<br>
File "guardian_sum.py", line 45, in scan<br>
l.append(error_ip)<br>
AttributeError: 'string' object has no attribute 'append'<br>
<br>
Why does the error_dict.get() return a string?<br>
<br>
Thanks in advance,<br>
<br>
Nate Custer<br>
<br>
====================================Begin Code ==========================<br>
error_dict = {}<br>
<br>
def scan():<br>
guardian = open("/var/log/guardian/guardian.log", 'r')<br>
ipchains = open("/home/nsc/ipchains.log", 'w')<br>
odd = open("/home/nsc/odd.log", 'w')<br>
<br>
nums = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' ]<br>
days = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']<br>
blocked_host = []<br>
<br>
while 1:<br>
# read the line<br>
line = guardian.readline()<br>
if not line: break<br>
<br>
if line[:3] in days:<br>
<br>
word = string.split (line)<br>
for w in word:<br>
if 'IDS' == w[:3]:<br>
error = w<br>
if w[0] in nums:<br>
error_ip = w<br>
<br>
<br>
if error_dict.has_key(error):<br>
l = error_dict.get(error)<br>
l.append(error_ip)<br>
append = {error: l}<br>
error_dict.update (append)<br>
else:<br>
x = [`error_ip`]<br>
append = {error: x}<br>
error_dict.update (append)</BODY>
</HTML>
--=-AGVnSkuT5LiNtNpkWBA5--