On Sun, May 24, 2009 at 10:18 PM, Paras K. <para...@gmail.com> wrote:
> Hello, > > I came across your answer / assistance on the IP range. I am fairly new to > the python world of programming. However, up to this point I have always > been able to get my programs to work by reading the books or following the > guides I find through google.com > > Here is what I have to do: > > I have to read a number of cvs files into 1 large file. (I have been able > to get that done through a perl script). But after I get it into a large cvs > file, I need to be able to look at each row and see if it falls within a > specific IP ranges. > > IP Ranges: > > 162.x.x.x > 151.130.x.x > 145.x.x.x > > These are just some examples of the IP ranges. > > The csv file has data like below: > 63.145.40.32 Gnutella File Search 14 5/15/2009 0:48 151.40.133.25 Gnutella > File Search 14 5/14/2009 16:21 145.133.19.147 BitTorrent Client Activity > 13 5/14/2009 19:20 <snip> > You know, unless you have an ulterior reason for merging all the files, you could probably just read each of them with a loop in python. Or use python to build the main file - which would eliminate your need for that error check. Assuming that the first element in the line will always be the IP, this should help: In [12]: myline = '192.168.1.1 Gnutella File Search 24 5/15/2009 0:48' In [15]: ip = myline.split(' ')[0] In [16]: split_ip = ip.split('.') In [17]: split_ip Out[17]: ['192', '168', '1', '1'] HTH, Wayne
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor