Skip to main content
added 30 characters in body
Source Link
kikito
  • 53k
  • 34
  • 156
  • 198

I might be wrong, but this looks like a job for the ||= operator.

def get_foo(): return self._foo |= Bar() 

My Perl is rusty at best, but ||= seems to return an R-value, so the return should work.

Edit: Woopsie, this is Python. It doesn't have a ||=. Bummer.

Then I'd use the simulated ternary operator:

def get_foo() self._foo = self._foo ==is None and Bar() or self._foo return self._foo 

Edit 2: Python has a real ternary operator. Use it instead of the above.

def get_foo() self._foo = Bar() if self._foo ==is None else self._foo return self._foo 

I might be wrong, but this looks like a job for the ||= operator.

def get_foo(): return self._foo |= Bar() 

My Perl is rusty at best, but ||= seems to return an R-value, so the return should work.

Edit: Woopsie, this is Python. It doesn't have a ||=. Bummer.

Then I'd use the simulated ternary operator:

def get_foo() self._foo = self._foo == None and Bar() or self._foo return self._foo 

Edit 2: Python has a real ternary operator

def get_foo() self._foo = Bar() if self._foo == None else self._foo return self._foo 

I might be wrong, but this looks like a job for the ||= operator.

def get_foo(): return self._foo |= Bar() 

My Perl is rusty at best, but ||= seems to return an R-value, so the return should work.

Edit: Woopsie, this is Python. It doesn't have a ||=. Bummer.

Then I'd use the simulated ternary operator:

def get_foo() self._foo = self._foo is None and Bar() or self._foo return self._foo 

Edit 2: Python has a real ternary operator. Use it instead of the above.

def get_foo() self._foo = Bar() if self._foo is None else self._foo return self._foo 
added 148 characters in body
Source Link
kikito
  • 53k
  • 34
  • 156
  • 198

I might be wrong, but this looks like a job for the ||= operator.

def get_foo(): return self._foo |= Bar() 

My Perl is rusty at best, but ||= seems to return an R-value, so the return should work.

Edit: Woopsie, this is Python. It doesn't have a ||=. Bummer.

Then I'd use the simulated ternary operator:

def get_foo() self._foo = self._foo == None and Bar() or self._foo return self._foo 

Edit 2: Python has a real ternary operator

def get_foo() self._foo = Bar() if self._foo == None else self._foo return self._foo 

I might be wrong, but this looks like a job for the ||= operator.

def get_foo(): return self._foo |= Bar() 

My Perl is rusty at best, but ||= seems to return an R-value, so the return should work.

Edit: Woopsie, this is Python. It doesn't have a ||=. Bummer.

Then I'd use the simulated ternary operator:

def get_foo() self._foo = self._foo == None and Bar() or self._foo return self._foo 

I might be wrong, but this looks like a job for the ||= operator.

def get_foo(): return self._foo |= Bar() 

My Perl is rusty at best, but ||= seems to return an R-value, so the return should work.

Edit: Woopsie, this is Python. It doesn't have a ||=. Bummer.

Then I'd use the simulated ternary operator:

def get_foo() self._foo = self._foo == None and Bar() or self._foo return self._foo 

Edit 2: Python has a real ternary operator

def get_foo() self._foo = Bar() if self._foo == None else self._foo return self._foo 
Python and Perl both begin with P
Source Link
kikito
  • 53k
  • 34
  • 156
  • 198

I might be wrong, but this looks like a job for the ||= operator.

def get_foo(): return self._foo ||=|= Bar() 

My Perl is rusty at best, but ||= seems to return an R-value, so the return should work.

Edit: Woopsie, this is Python. It doesn't have a ||=. Bummer.

Then I'd use the simulated ternary operator:

def get_foo() self._foo = self._foo == None and Bar() or self._foo return self._foo 

I might be wrong, but this looks like a job for the ||= operator.

def get_foo(): return self._foo ||= Bar() 

My Perl is rusty at best, but ||= seems to return an R-value, so the return should work.

I might be wrong, but this looks like a job for the ||= operator.

def get_foo(): return self._foo |= Bar() 

My Perl is rusty at best, but ||= seems to return an R-value, so the return should work.

Edit: Woopsie, this is Python. It doesn't have a ||=. Bummer.

Then I'd use the simulated ternary operator:

def get_foo() self._foo = self._foo == None and Bar() or self._foo return self._foo 
Source Link
kikito
  • 53k
  • 34
  • 156
  • 198
Loading