Skip to content

Commit 46975aa

Browse files
committed
Make pyspark shell pythonstartup work under python3
This replaces the execfile used for running custom python shell scripts with explicit open, compile and exec. The reason is to make the pythonstartup option compatible with python3.
1 parent 76540b6 commit 46975aa

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

python/pyspark/shell.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,6 @@
7676
# which allows us to execute the user's PYTHONSTARTUP file:
7777
_pythonstartup = os.environ.get('OLD_PYTHONSTARTUP')
7878
if _pythonstartup and os.path.isfile(_pythonstartup):
79-
execfile(_pythonstartup)
79+
with open(_pythonstartup) as f:
80+
code = compile(f.read(), _pythonstartup, 'exec')
81+
exec(code)

0 commit comments

Comments
 (0)