File tree 1 file changed +24
-2
lines changed
packages/python/plotly/plotly/io
1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -156,7 +156,7 @@ def write_image(
156
156
157
157
file: str or writeable
158
158
A string representing a local file path or a writeable object
159
- (e.g. an open file descriptor)
159
+ (e.g. a pathlib.Path object or an open file descriptor)
160
160
161
161
format: str or None
162
162
The desired image format. One of
@@ -258,7 +258,29 @@ def write_image(
258
258
with open (file , "wb" ) as f :
259
259
f .write (img_data )
260
260
else :
261
- file .write (img_data )
261
+ # Handle a pathlib.Path object
262
+ # ----------------------------
263
+ try :
264
+ file .write_bytes (img_data )
265
+ return
266
+ except AttributeError :
267
+ pass
268
+ # Handle an open file descriptor
269
+ # ------------------------------
270
+ try :
271
+ file .write (img_data )
272
+ return
273
+ except AttributeError :
274
+ pass
275
+ # Handlers failed
276
+ # ---------------
277
+ raise ValueError (
278
+ """
279
+ The 'file' argument '{file}' is not a string, pathlib.Path object, or file descriptor.
280
+ """ .format (
281
+ file = file
282
+ )
283
+ )
262
284
263
285
264
286
def full_figure_for_development (fig , warn = True , as_dict = False ):
You can’t perform that action at this time.
0 commit comments