File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -332,13 +332,18 @@ pyIncludes backend = ["import matplotlib"
332
332
," axes = [plot.gca()]"
333
333
," ax = axes[0]" ]
334
334
335
+ -- | These will be Python strings and slashes would cause unwanted control characters.
336
+ escapeSlashes (' \\ ' : cs) = ' \\ ' : ' \\ ' : escapeSlashes cs
337
+ escapeSlashes (c: cs) = c: escapeSlashes cs
338
+ escapeSlashes [] = []
339
+
335
340
-- | The python command that reads external data into the python data array
336
341
pyReadData :: [Char ] -> [[Char ]]
337
- pyReadData filename = [" data = json.loads(open('" ++ filename ++ " ').read())" ]
342
+ pyReadData filename = [" data = json.loads(open('" ++ escapeSlashes filename ++ " ').read())" ]
338
343
339
344
-- | The python command that reads an image into the img variable
340
345
pyReadImage :: [Char ] -> [[Char ]]
341
- pyReadImage filename = [" img = mpimg.imread('" ++ filename ++ " ')" ]
346
+ pyReadImage filename = [" img = mpimg.imread('" ++ escapeSlashes filename ++ " ')" ]
342
347
343
348
-- | Detach python so we don't block (TODO This isn't working reliably)
344
349
pyDetach :: [[Char ]]
@@ -353,7 +358,7 @@ pyOnscreen = ["plot.draw()"
353
358
354
359
-- | Python code that saves a figure
355
360
pyFigure :: [Char ] -> [[Char ]]
356
- pyFigure output = [" plot.savefig('" ++ output ++ " ')" ]
361
+ pyFigure output = [" plot.savefig('" ++ escapeSlashes output ++ " ')" ]
357
362
358
363
-- | Create a positional option
359
364
o1 x = P $ toPythonOpt x
You can’t perform that action at this time.
0 commit comments