Skip to content

Commit 08b9a3a

Browse files
authored
Merge pull request #506 from NetSys/2to3
Fix raw_input and input confusion
2 parents 34ce577 + 62b1298 commit 08b9a3a

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

bessctl/cli.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,11 @@ def print_banner(self):
371371
def process_one_line(self):
372372
if self.interactive:
373373
try:
374-
# Hack for Python 2/3 compatibility
375-
if hasattr(__builtins__, 'raw_input'):
376-
line = raw_input(self.get_prompt())
377-
else:
378-
line = input(self.get_prompt())
374+
try:
375+
prompt = raw_input # Python 2
376+
except NameError:
377+
prompt = input # Python 3
378+
line = prompt(self.get_prompt())
379379
except KeyboardInterrupt:
380380
self.fout.write('\n')
381381
return

bessctl/commands.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,12 +546,12 @@ def warn(cli, msg, func, *args):
546546
cli.rl.set_completer(cli.complete_dummy)
547547

548548
try:
549-
# Hack for Python 2/3 compatibility
550-
if hasattr(__builtins__, 'raw_input'):
551-
resp = raw_input(
552-
'WARNING: %s Are you sure? (type "yes") ' % msg)
553-
else:
554-
resp = input('WARNING: %s Are you sure? (type "yes") ' % msg)
549+
try:
550+
prompt = raw_input # Python 2
551+
except NameError:
552+
prompt = input # Python 3
553+
554+
resp = prompt('WARNING: %s Are you sure? (type "yes") ' % msg)
555555

556556
if resp.strip() == 'yes':
557557
func(cli, *args)

0 commit comments

Comments
 (0)