Skip to content

Commit 0eea3ac

Browse files
Add example Generating And Saving An Image File
1 parent c4016fb commit 0eea3ac

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ This example shows how to use Judge0 Python SDK to:
568568
2. Read the files after the execution which were created during the execution.
569569

570570
```python
571+
# pip install judge0
571572
import judge0
572573
from judge0 import Filesystem, File, Submission
573574

@@ -601,6 +602,7 @@ print(result.post_execution_filesystem.find("./my_dir2/my_file2.txt"))
601602
This example shows how to use Judge0 Python SDK with your own Judge0 instance.
602603

603604
```python
605+
# pip install judge0
604606
import judge0
605607

606608
client = judge0.Client("http://127.0.0.1:2358")
@@ -617,3 +619,24 @@ int main() {
617619
result = judge0.run(client=client, source_code=source_code, language=judge0.C)
618620
print(result.stdout)
619621
```
622+
623+
### Generating And Saving An Image File
624+
625+
```python
626+
# pip install judge0
627+
import judge0
628+
629+
source_code = """
630+
import matplotlib.pyplot as plt
631+
632+
plt.plot([x for x in range(10)], [x**2 for x in range(10)])
633+
plt.savefig("chart.png")
634+
"""
635+
636+
result = judge0.run(source_code=source_code, language=judge0.PYTHON_FOR_ML)
637+
638+
image = result.post_execution_filesystem.find("chart.png")
639+
with open(image.name, "wb") as f:
640+
f.write(image.content)
641+
print(f"Generated image saved as: {image.name}\n")
642+
```

0 commit comments

Comments
 (0)