Re: [Python-ideas] Conditional Assignment in If Statement

2016-10-21 Thread Sven R. Kunze
On 18.10.2016 00:11, Michael duPont wrote: What does everyone think about: if foo = get_foo(): bar(foo) as a means to replace: foo = get_foo() if not foo: bar(foo) del foo Might there be some better syntax or a different keyword? I constantly run into this sort of use case. Befor

Re: [Python-ideas] Conditional Assignment in If Statement

2016-10-17 Thread Michael duPont
It was not my intention to declare those to be similar, just as a furthering train of thought. I agree that using "as" is a much more Pythonic syntax. I'm sure there was (and will be) some discussion as to whether it should operate like "if foo:" or "if foo is not None:". I'll look a bit further in

Re: [Python-ideas] Conditional Assignment in If Statement

2016-10-17 Thread Chris Angelico
On Tue, Oct 18, 2016 at 9:11 AM, Michael duPont wrote: > What does everyone think about: > > if foo = get_foo(): > bar(foo) > > as a means to replace: > > foo = get_foo() > if not foo: > bar(foo) > del foo > > Might there be some better syntax or a different keyword? I constantly run > in

[Python-ideas] Conditional Assignment in If Statement

2016-10-17 Thread Michael duPont
In the spirit of borrowing from other languages, there’s a particular bit of functionality from Swift that I’ve really wanted to have in Python. To preface, Swift uses var and let (static) when variables are created. It also supports optionals which allows a variable to be either some value or n