Assignment-in-conditional

X

xamdam

I am not sure if this came up before, but I would love to have an
'assignment-in-conditional' form in python, e.g

pat = re.compile('something')

if m = pat.match(s):
m.group(1)

Of course there is some concern about accidentally using '=' instead of
'=='. One possible solution is to do what the 'with' statement does:

if pat.match(s) as m:
...

a little ugly but not too much worse that with itself..

what do you guys think?

- max
 
G

Georg Brandl

xamdam said:
I am not sure if this came up before, but I would love to have an
'assignment-in-conditional' form in python, e.g

pat = re.compile('something')

if m = pat.match(s):
m.group(1)

Of course there is some concern about accidentally using '=' instead of
'=='. One possible solution is to do what the 'with' statement does:

if pat.match(s) as m:
...

a little ugly but not too much worse that with itself..

what do you guys think?

It has been proposed before (a few times even), and Guido doesn't like it.

Georg
 
X

xamdam

Thanks for the FAQ, and for the 'casm ;)

What do you think about using alternative syntax (something like 'as')

- max
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top