File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -216,11 +216,17 @@ def callback(group):
216216
217217def exec_code (interpreter , args ):
218218 """
219- Helper to execute code in a given interpreter. args should be a [faked]
220- sys.argv
219+ Helper to execute code in a given interpreter, e.g. to implement the behavior of python3 [-i] file.py
220+
221+ args should be a [faked] sys.argv.
221222 """
222- with open (args [0 ]) as sourcefile :
223- source = sourcefile .read ()
223+ try :
224+ with open (args [0 ]) as sourcefile :
225+ source = sourcefile .read ()
226+ except OSError as e :
227+ # print an error and exit (if -i is specified the calling code will continue)
228+ print (f"bpython: can't open file '{ args [0 ]} : { e } " , file = sys .stderr )
229+ raise SystemExit (e .errno )
224230 old_argv , sys .argv = sys .argv , args
225231 sys .path .insert (0 , os .path .abspath (os .path .dirname (args [0 ])))
226232 spec = importlib .util .spec_from_loader ("__console__" , loader = None )
You can’t perform that action at this time.
0 commit comments