On 2018-04-27 21:04:49 -0700, Ed Manning wrote: > Here is the source code. > > > import re > > > log = open("csg.txt", "r") # Opens a file call session.txt > regex = re.compile(r'policy id \d+') # search for the policy ID > regex1 = re.compile(r'log count \d+') # search for the policy ID > > for match in log: > x = regex.findall(match) > y = regex1.findall(match) > > q = x + y > print(q) > > > The problem I am having i when it print out ti looks like this > > > L'Policy ID 243"| > [] > [] > [] > [] > [] > [] > [] > [] > {'log count 777,"] > > > > How so I fix the code sone that it does not print empty []
Print the result only if findall actually found something. hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | h...@hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>
signature.asc
Description: PGP signature
-- https://mail.python.org/mailman/listinfo/python-list