Skip to content

Commit

Permalink
Use pathlib instead of os in IPython/lib/demo
Browse files Browse the repository at this point in the history
  • Loading branch information
ChandanChainani committed Oct 13, 2022
1 parent dc08a33 commit 76a4771
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions IPython/lib/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 76a4771

Please sign in to comment.