from IPython import display
display.display(display.Markdown('.'))
---------------------------------------------------------------------------
IsADirectoryError Traceback (most recent call last)
<ipython-input-6-0a1e025990e8> in <cell line: 0>()
1 from IPython import display
----> 2 display.display(display.Markdown('.'))
/usr/local/lib/python3.11/dist-packages/IPython/core/display.py in __init__(self, data, url, filename, metadata)
635 self.metadata = {}
636
--> 637 self.reload()
638 self._check_data()
639
/usr/local/lib/python3.11/dist-packages/IPython/core/display.py in reload(self)
660 """Reload the raw data from file or URL."""
661 if self.filename is not None:
--> 662 with open(self.filename, self._read_flags) as f:
663 self.data = f.read()
664 elif self.url is not None:
IsADirectoryError: [Errno 21] Is a directory: '.'
This is because this code explicitly checks whether the data argument to display.Markdown is an existing path, and if so, reads that path instead of displaying the text itself.
This also leads to a weird side effects, allowing to display the files one may not intend to display:
Is it a good idea to decide whether to read a file or to display the text depending on whether the text resolves to an existing path? Perhaps this should be done with a flag instead, i.e. if the user explicitly passes filename=?
This is because this code explicitly checks whether the
dataargument todisplay.Markdownis an existing path, and if so, reads that path instead of displaying the text itself.This also leads to a weird side effects, allowing to display the files one may not intend to display:
Is it a good idea to decide whether to read a file or to display the text depending on whether the text resolves to an existing path? Perhaps this should be done with a flag instead, i.e. if the user explicitly passes
filename=?