Skip to content

Commit 3d5e597

Browse files
authored
Fix devnull error on python2.7
1 parent acca8d5 commit 3d5e597

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

nltk/internals.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ def java(cmd, classpath=None, stdin=None, stdout=None, stderr=None, blocking=Tru
109109
:raise OSError: If the java command returns a nonzero return code.
110110
"""
111111

112-
subprocess_output_dict = {'pipe': subprocess.PIPE, 'stdout': subprocess.STDOUT, 'devnull': subprocess.DEVNULL}
112+
try:
113+
from subprocess import DEVNULL
114+
except ImportError:
115+
DEVNULL = open(os.devnull, 'wb')
116+
subprocess_output_dict = {'pipe': subprocess.PIPE, 'stdout': subprocess.STDOUT, 'devnull': DEVNULL}
113117

114118
stdin = subprocess_output_dict.get(stdin, stdin)
115119
stdout = subprocess_output_dict.get(stdout, stdout)

0 commit comments

Comments
 (0)