MCPcopy Index your code
hub / github.com/python/cpython / save

Method save

Lib/turtle.py:1532–1563  ·  view source on GitHub ↗

Save the drawing as a PostScript file Arguments: filename -- a string, the path of the created file. Must end with '.ps' or '.eps'. Optional arguments: overwrite -- boolean, if true, then existing files will be overwritten Example (for a

(self, filename, *, overwrite=False)

Source from the content-addressed store, hash-verified

1530 return self._resize(canvwidth, canvheight, bg)
1531
1532 def save(self, filename, *, overwrite=False):
1533 """Save the drawing as a PostScript file
1534
1535 Arguments:
1536 filename -- a string, the path of the created file.
1537 Must end with '.ps' or '.eps'.
1538
1539 Optional arguments:
1540 overwrite -- boolean, if true, then existing files will be overwritten
1541
1542 Example (for a TurtleScreen instance named screen):
1543 >>> screen.save('my_drawing.eps')
1544 """
1545 filename = Path(filename)
1546 if not filename.parent.exists():
1547 raise FileNotFoundError(
1548 f"The directory '{filename.parent}' does not exist."
1549 " Cannot save to it."
1550 )
1551 if not overwrite and filename.exists():
1552 raise FileExistsError(
1553 f"The file '{filename}' already exists. To overwrite it use"
1554 " the 'overwrite=True' argument of the save function."
1555 )
1556 if (ext := filename.suffix) not in {".ps", ".eps"}:
1557 raise ValueError(
1558 f"Unknown file extension: '{ext}',"
1559 " must be one of {'.ps', '.eps'}"
1560 )
1561
1562 postscript = self.cv.postscript()
1563 filename.write_text(postscript)
1564
1565 onscreenclick = onclick
1566 resetscreen = reset

Callers

nothing calls this directly

Calls 5

existsMethod · 0.95
write_textMethod · 0.95
PathClass · 0.90
postscriptMethod · 0.80
existsMethod · 0.45

Tested by

no test coverage detected