Re: [Pyparsing] ip address
Brought to you by:
ptmcg
From: Gre7g L. <haf...@ya...> - 2009-01-16 00:33:59
|
From: dikshie <di...@gm...> To: pyp...@li... Sent: Thursday, January 15, 2009 4:23:44 PM Subject: [Pyparsing] ip address > in_file = open(sys.argv[1], "r") > integer = Word( nums ) > ipAddress = delimitedList( integer, ".", combine=True ) This will get any number of integers... even one. You want four specifically. > ip = ipAddress.parseString(line) line? What's line? You're getting an un-helpful error here because you did a "from pyparsing import *". That's a bad plan. Never do an "import *". > print ip Try this instead: in_file = open(sys.argv[1], "r").read() integer = Word( nums ) ipAddress = Combine(integer + "." + integer + "." + integer + "." + integer) ip = ipAddress.searchString(in_file) print ip Gre7g |