Something keeps nibbling on my list

michael mhyoung at valdosta.edu
Fri Apr 20 10:38:50 EDT 2001


Here is the hosts.deny file. The IP addresses, of course, have been changed.
ther are the same number of ip addresses here as the real 1. The first 2 lines
are not being printed. Sorry for not including this file at first.

thx
     Michael

########## START FILE ###############
#
# hosts.deny This file describes the names of the hosts which are
#  *not* allowed to use the local INET services, as decided
#  by the '/usr/sbin/tcpd' server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow.  In particular
# you should know that NFS uses portmap!

127.0.0.0
127.0.0.1
127.0.0.2
127.0.0.3
127.0.0.4
127.0.0.5
127.0.0.6
127.0.0.7
127.0.0.8
127.0.0.9
127.0.0.10
127.0.0.11
127.0.0.12
127.0.0.13
127.0.0.14
127.0.0.15
127.0.0.16
127.0.0.17
127.0.0.18
127.0.0.19
127.0.0.20
127.0.0.21
127.0.0.22
127.0.0.23
127.0.0.24
127.0.0.25
127.0.0.26
127.0.0.27
127.0.0.28
127.0.0.29
127.0.0.30
127.0.0.31
127.0.0.32
127.0.0.33
127.0.0.34
127.0.0.35
127.0.0.36
127.0.0.37
127.0.0.38
127.0.0.39
127.0.0.40
127.0.0.41
127.0.0.42
127.0.0.43
127.0.0.44
127.0.0.45
127.0.0.46
127.0.0.47
127.0.0.48
127.0.0.49
127.0.0.50
127.0.0.51
127.0.0.52
127.0.0.53
127.0.0.54
127.0.0.55
127.0.0.56
127.0.0.57
127.0.0.58
127.0.0.59
127.0.0.60
127.0.0.61
127.0.0.62
127.0.0.63
127.0.0.64
127.0.0.65
127.0.0.66
127.0.0.67
127.0.0.68
127.0.0.69
127.0.0.70
127.0.0.71
127.0.0.72
127.0.0.73
127.0.0.74
127.0.0.75
127.0.0.76
127.0.0.77
127.0.0.78
127.0.0.79
127.0.0.80
127.0.0.81
127.0.0.82
127.0.0.83
127.0.0.84
127.0.0.85
127.0.0.86
127.0.0.87
127.0.0.88
127.0.0.89
127.0.0.90
127.0.0.91
127.0.0.92
127.0.0.93
127.0.0.94
127.0.0.95
127.0.0.96
127.0.0.97
127.0.0.98
127.0.0.99
127.0.0.100
127.0.0.101
127.0.0.102
127.0.0.103
127.0.0.104
127.0.0.105
127.0.0.106
127.0.0.107
127.0.0.108
127.0.0.109
127.0.0.110
127.0.0.111
127.0.0.112
127.0.0.113
127.0.0.114
127.0.0.115
127.0.0.116
127.0.0.117
127.0.0.118
127.0.0.119
127.0.0.120
127.0.0.121
127.0.0.122
127.0.0.123
127.0.0.124
127.0.0.125
127.0.0.126
127.0.0.127
########### END FILE ################



Geoffrey Gerrietts wrote:

> A couple quick comments, then a question.
>
> First:
> when initializing the list:
> >>> l = []
> that works, and that way you wouldn't need to remove the "1" later.
>
> Second:
>
> you were shown the 'in' technique:
> >>> if buf in list
> a variant involves sticking things into a dictionary and testing with
> has_key():
> >>> if not dict.has_key(buf):
> >>>     dict[buf] = 1
> >>> return dict
>
> The question:
>
> what are the first two lines of the file? what was your expected output? it
> might help if we could trace the data flow.
>
> thanks,
> --G.
>
> ---
> Geoff Gerrietts <geoff at homegain.com>
> Software Engineer, HomeGain.com
> 510-655-0800 x4320
>
>
> > -----Original Message-----
> > From: michael [mailto:mhyoung at valdosta.edu]
> > Sent: Wednesday, April 18, 2001 11:34 AM
> > To: python-list at python.org
> > Subject: Something keeps nibbling on my list
> >
> >
> > My program reads a file and copies it into a list, line by
> > line. Then
> > writes the list to another file. for some reason the first 2
> > lines from
> > the first file are missing from the second file. i know that
> > they are
> > being read into the list because i print the whole list out
> > and they are
> > there. Can someone please help? The entire program is below.
> >
> >      TIA
> >             Michael
> >
> > ################  Start program #######################
> >
> >
> > #!/usr/local/bin/python
> >
> > #This program reads the hosts.deny file, removes duplicate entries and
> > #sorts them. It then sends the output to another file.
> > #This program requires Python 2.0.
> >
> > import sys
> > import string
> >
> > FILENAME = "/etc/hosts.deny"   #The file the input is read from.
> > TEMPFILE = "./hosts.deny.test"   #The file the output is written to.
> > EXCLUDE=''   #Lines beginning with this should not be printed.
> >
> > def get_line() :
> >   buf = f.readline()
> >   if (buf and buf[0] == EXCLUDE):
> >     return 0
> >   else:
> >     return buf
> >
> >
> > def is_this_a_dup(buf, l) :
> >   if (l and buf):
> >     results = l.count(buf)
> >     if (results > 0):
> >       return l
> >     else:
> >       l.append(buf)
> >       return l
> >   else:
> >     l = buf
> >     return l
> >
> >
> > f = open(FILENAME, "r")
> >
> > l = ["1"]   #This is just to avoid the "NameError: There is no
> >             #   variable named 'l'". It can be taken care of later.
> >
> > while 1:
> >   buf = get_line()
> >   if (buf == ''):
> >     break
> >   if (buf == 0):   # If 0 is returned then the line read on this loop
> > begins
> >     continue       #    with the EXCLUDE char and is not to be used.
> >   else:
> > #    sys.stdout.write(buf)
> >     l = is_this_a_dup(buf, l)
> >
> > print l
> >
> > l.remove("1")   #Removes the 1 that we put into the list at the
> > beginning of
> >                 #    the program.
> > l.sort()
> >
> > for i in l:
> >   sys.stdout.write(i)
> >
> > g = open(TEMPFILE, "w")
> > g.writelines(l)
> > g.close()
> >
> > f.close()
> >
> >
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >





More information about the Python-list mailing list