assignment in if

Gary Wessle phddas at yahoo.com
Tue May 2 19:13:08 EDT 2006


Hi

is there a way to make an assignment in the condition of "if" and use
it later, e.g.

nx = re.compile('regex')
if nx.search(text):
   funCall(text, nx.search(text))

nx.search(text) is evaluated twice, I was hoping for something like

nx = re.compile('regex')
if x = nx.search(text):
   funCall(text, x))

thanks



More information about the Python-list mailing list