-1

In this python code line 256 to 266

this use run in sarge

        p = run(
            cmd,
            input=self.feeder,
            async_=True,
            stdout=self.stdout or Capture(timeout=0.1, buffer_size=1),
            stderr=self.stderr or Capture(timeout=0.1, buffer_size=1),
            cwd=self.cwd,
            env=self.env,
            shell=self.shell,
            **run_args
        )

I trouble with understand OR logical operator stdout=self.stdout or Capture(timeout=0.1, buffer_size=1)

this OR two object in parameter ?

3 Answers3

0

If stdout=self.stdout is true and Capture(timeout=0.1, buffer_size=1) is true, then the entire statement is true.

If stdout=self.stdout is true and Capture(timeout=0.1, buffer_size=1) is false, then the entire statement is true, and vice versa.

If stdout=self.stdout is false and Capture(timeout=0.1, buffer_size=1) is false, then the entire statement is false.

rzuberi
  • 11
  • 1
0

It will use the first "truthy" variable. In your example if self.stdout is null, it will then assign to Capture(timeout=0.1, buffer_size=1). Here's a great resource https://realpython.com/python-or-operator/ Look to the section regarding "Non-Boolean Contexts"

Zach W
  • 194
  • 11
  • Hi I read Your link in realpython But really have not see any "reference" or example show can use "or" to return one function from two other question what happen if both is not null ! – maziar navahan Jul 28 '21 at 06:23
0

For my understanding, OR is used when you want to specify a default value for parameter (second statement) if first statement is not available (None).

In your case, if self.stdout=None, stdout will have value of second statement (Capture(timeout=0.1, buffer_size=1)).