From fb538e87f5d4b1fac427f0fec69c07de9244e53b Mon Sep 17 00:00:00 2001 From: Abdelhakim Qbaich Date: Thu, 20 Oct 2022 05:16:08 +0000 Subject: [PATCH] Set cell_number to 0 if history is not available --- packages/python/plotly/plotly/io/_base_renderers.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/python/plotly/plotly/io/_base_renderers.py b/packages/python/plotly/plotly/io/_base_renderers.py index f4ccd0c0f88..6e51ab43955 100644 --- a/packages/python/plotly/plotly/io/_base_renderers.py +++ b/packages/python/plotly/plotly/io/_base_renderers.py @@ -608,12 +608,15 @@ def to_mimebundle(self, fig_dict): return {"text/html": iframe_html} def build_filename(self): - ip = IPython.get_ipython() if IPython else None - cell_number = list(ip.history_manager.get_tail(1))[0][1] + 1 if ip else 0 - filename = "{dirname}/figure_{cell_number}.html".format( + if IPython: + ip = IPython.get_ipython() + cell_number = next(ip.history_manager.get_tail(1), (0, -1, ""))[1] + 1 + else: + cell_number = 0 + + return "{dirname}/figure_{cell_number}.html".format( dirname=self.html_directory, cell_number=cell_number ) - return filename def build_url(self, filename): return filename