|
17 | 17 | # Download a file |
18 | 18 | downloaded = codebox.download("example.txt") |
19 | 19 | content = downloaded.get_content() # Returns b"Hello from CodeBox!" |
| 20 | +print("Content:\n", content, sep="") |
20 | 21 |
|
21 | 22 | # List files |
22 | | -files = codebox.list_files() # Returns list[RemoteFile] |
| 23 | +files = codebox.list_files() |
| 24 | +print("\nFiles:\n", "\n".join(f.__repr__() for f in files), sep="") |
23 | 25 |
|
24 | 26 | # 3. Package Management |
25 | 27 | # Install packages |
26 | 28 | codebox.install("pandas") |
27 | 29 |
|
28 | 30 | # List installed packages |
29 | 31 | packages = codebox.list_packages() |
| 32 | +print("\nFirst 10 packages:\n", "\n".join(packages[:10]), sep="") |
30 | 33 |
|
31 | 34 | # 4. Variable Management |
32 | 35 | # Execute code that creates variables |
|
38 | 41 |
|
39 | 42 | # Show all variables |
40 | 43 | variables = codebox.show_variables() |
41 | | -print(variables) # Shows dict with all variables and their values |
| 44 | +print("\nVariables:\n", "\n".join(f"{k}={v}" for k, v in variables.items()), sep="") |
42 | 45 |
|
43 | 46 | # 5. Plotting with Matplotlib |
44 | 47 | plot_code = """ |
|
59 | 62 | import time |
60 | 63 | time.sleep(1) |
61 | 64 | """): |
| 65 | + # will not print when using "local" as api_key |
| 66 | + # due to stdout being captured in the background |
62 | 67 | print(chunk.content, end="") |
63 | 68 |
|
64 | 69 | # 7. Bash Commands |
|
73 | 78 | # 8. Error Handling |
74 | 79 | result = codebox.exec("1/0") |
75 | 80 | if result.errors: |
76 | | - print("Error occurred:", result.errors[0]) |
| 81 | + print("\nError occurred:", result.errors[0]) |
0 commit comments