Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
material
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PythonCourse
material
Commits
f48858c9
Commit
f48858c9
authored
3 years ago
by
Ralf Mueller
Browse files
Options
Downloads
Patches
Plain Diff
add examples for errors with/without messages
parent
288ab074
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#11298
passed
3 years ago
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
DEBUG.md
+58
-3
58 additions, 3 deletions
DEBUG.md
with
58 additions
and
3 deletions
DEBUG.md
+
58
−
3
View file @
f48858c9
# How to work with broken programs
Example: NCL_color_1.py
Error:
# Debugging: How to work with broken programs
What is the Problem? Why debugging? Everything works, right?
## No! Every real world program has errors. Amen
Two options:
-
easy: the program crashes and shows error messages
-
hard: the program seem to work properly, but the results are unexpected
### Example (easy)
Let's take an example of geocat, because they offer so many nice plots:
[
NCL_color_1.py
](
./scripts/NCL_color_1.py
)
There should be some nice errors in it, too ;-)
Lessions:
-
Understand your environment and its limitations
-
Read error messages and warning. They are your best friends (most of the time)
An common example of a message hard to understand:
```
python
print
(
"
a = {0}
"
.
format
(
55
)
```
throws this:
```
shell
SyntaxError: unexpected EOF
while
parsing
```
Keep it in mind
### Example (hard)
```
python
import
sys
def
sum
(
a
,
b
):
return
a
+
b
if
__name__
==
"
__main__
"
:
# first some tests
print
(
"
2 = {0}
"
.
format
(
sum
(
1
,
1
)))
print
(
"
5 = {0}
"
.
format
(
sum
(
1
,
4
)))
print
(
"
4 = {0}
"
.
format
(
sum
(
2
,
2
)))
# now some user given numbers
a
=
sys
.
argv
[
1
]
b
=
sys
.
argv
[
2
]
print
(
"
a = {0}
"
.
format
(
a
))
print
(
"
b = {0}
"
.
format
(
b
))
print
(
"
sum = {0}
"
.
format
(
sum
(
a
,
b
)))
```
### Example (harder)
What should be the result?
```
python
0.3
==
0.1
+
0.2
True
or
False
#???
```
It's quite obvious, isn't it? Try it!
#
Problem: What to do, when the error message is crap
# printf debugger .. or print
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment