diff --git a/IPython/lib/demo.py b/IPython/lib/demo.py index ebffd54abde..f3295924b63 100644 --- a/IPython/lib/demo.py +++ b/IPython/lib/demo.py @@ -179,12 +179,11 @@ # #***************************************************************************** -import os import re import shlex import sys import pygments -from pathlib import Path +from pathlib import Path, PurePath from IPython.utils.text import marquee from IPython.utils import openpy @@ -251,8 +250,7 @@ def __init__(self,src,title='',arg_str='',auto_all=None, format_rst=False, # Assume it's a string or something that can be converted to one self.fname = src if title == '': - (filepath, filename) = os.path.split(src) - self.title = filename + self.title = PurePath(src).name else: self.title = title self.sys_argv = [src] + shlex.split(arg_str) @@ -405,7 +403,7 @@ def edit(self,index=None): filename = self.shell.mktempfile(self.src_blocks[index]) self.shell.hooks.editor(filename, 1) - with open(Path(filename), "r", encoding="utf-8") as f: + with Path(filename).open("r", encoding="utf-8") as f: new_block = f.read() # update the source and colored block self.src_blocks[index] = new_block