If I understand what you want, you want to use
if ";" in line:
if not "X" in line:
etc.
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
Reminds me of the time I wrote a barebones css parser for myself. Good times.
Not sure what exactly what you're going at, but try:
for page in css:
f = open(page, "r")
lines = f.readlines()
count = 1
obcount = 0
ebcount = 0
probwithfile = False
for line in lines:
if not re.search("^{$", line) or not re.search("^}$", line):
if not re.search(".*;$", line):
print "hi"
scru
Posting Virtuoso
1,629 posts since Feb 2007
Reputation Points: 975
Solved Threads: 140
Excuse me but why use regex anyways:
>>> lines=['this ends with;','but this ends with:']
>>> print [ x for x in lines if x.endswith(';')]
['this ends with;']
>>>
siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
If you had stated what you were trying to do in the beginning, you would probably have a solution by now. First, are you trying to count the "{" and "}" characters? If so, try the code below and after that is working state what you want to do next. Whatever it is, you don't want it inside a
for match in re.finditer("{", line):
statement as that will perform the same re multiple times (once for every "{" found). Whoever supplied the re statements was either playing a joke or trying to prove how much smarter they were than you. Neither solves your problem, and there are other ways that will work, and that you will also understand. There is a programmer saying that goes something like, "Someone has a problem. They say 'I'll solve this with a regular expression.' Now they have two problems." If this doesn't do the count the way you want, post back.
for page in css:
f = open(page, "r")
lines = f.readlines()
count = 1
obcount = 0
ebcount = 0
scount = 0
probwithfile = False
for line in lines:
count = line.count("{")
obcount += count
ebcount += line.count( "}" )
print "total '{' = %d, and total '}' = %d" % (obcount, ebcount)
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714