I have a simple question that I can workaround, but I'd like to find the Pythonic way of doing it.
I'm using Python 3.1.2.
re.match() will return a match object if the regex is found and None if not. Basically, I need to do some stuff with the match object inside the "if" statement. I need to do several operations, but most of them revolve around using the returned match object.
I'd like to do the following, but Python doesn't accept the syntax.
Where I assign the match object to tmp, not testing for equality.
From my understanding, Python removed this functionality because it causes so many programming errors. What is the Pythonic way to do this?
I'm using Python 3.1.2.
Code:
xml = open('apps.xml', 'r')
for line in xml:
if re.match("<Application id=.*", line):
re.match() will return a match object if the regex is found and None if not. Basically, I need to do some stuff with the match object inside the "if" statement. I need to do several operations, but most of them revolve around using the returned match object.
I'd like to do the following, but Python doesn't accept the syntax.
Code:
if tmp = re.match("<Application id=.*", line):
From my understanding, Python removed this functionality because it causes so many programming errors. What is the Pythonic way to do this?