This page (revision-21) was last changed on 2025-07-30 13:27 by Murray Altheim

This page was created on 2025-07-30 02:24 by Murray Altheim

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note
21 2025-07-30 13:27 826 bytes Murray Altheim to previous

Page References

Incoming links Outgoing links

Version management

Difference between version and

At line 15 changed one line
There is a structure in Python called a {{try-except-finally}} __block__, which is ideal for a main.py file:
In Python there is a {{try-except-finally}} structure called a "compound statement" consisting of three separate __blocks__, which is ideal for a main.py file.
At line 17 added 2 lines
In the below example, there is a {{try}} block, followed by an {{except}} block, followed by a {{finally}} block. A {{try}} block must be followed by an {{except}} block and/or a {{finally}} block (you must have one of them).
At line 19 changed one line
\\# this is a comment
try:
At line 23 added 14 lines
print('hello world.') # remember to indent the insides of your blocks by 4 characters!
except Exception:
# this block is executed if there is an exception (error)
print('an error occurred.')
finally:
# this is always executed, no matter what
print('complete.')
%%
If you want to use the exception to print out an error message you need to assign it to a variable (in this case, we've used {{ex}}).
%%filename main.py %%
%%python
At line 24 removed one line
^^^^ 🠈 remember to indent the insides of your blocks by 4 characters!
At line 47 added one line