Use branch instead of ternary operator

This commit is contained in:
Eeo Jun 2016-03-31 15:36:46 +08:00
parent e34758bb2a
commit 8ea8b41d94
2 changed files with 11 additions and 2 deletions

View File

@ -85,9 +85,12 @@ def edit(filename=None, contents=None, use_tty=True):
f.write(contents)
args += [filename]
extra = {'stdout': open('/dev/tty', 'wb')} if use_tty else {}
proc = subprocess.Popen(args, close_fds=True, **extra)
stdout = None
if use_tty:
stdout = open('/dev/tty', 'wb')
proc = subprocess.Popen(args, close_fds=True, stdout=stdout)
proc.communicate()
with open(filename, mode='rb') as f:

6
test.py Normal file
View File

@ -0,0 +1,6 @@
import sys
import editor
cont = editor.edit(contents='ABC!',
use_tty='use_tty' in sys.argv)
sys.stdout.write(cont)