You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: slides_sources/source/exercises/html_renderer.rst
+27-1Lines changed: 27 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -93,7 +93,7 @@ It should have a ``render(file_out, ind = "")`` method that renders the tag and
93
93
94
94
The amount of each level of indentation should be set by the class attribute: ``indent``
95
95
96
-
NOTE: don't worry too much about indentation at this stage -- the primary goal is to get proper, compliant html. i.e. the opening and closing tags rendered correctly. Worry about cleaning up the indentation once you've got that working.
96
+
NOTE: don't worry too much about indentation at this stage -- the primary goal is to get proper, compliant html. i.e. the opening and closing tags rendered correctly. Worry about cleaning up the indentation once you've got that working. See "Note on indentation" below for more explaination.
97
97
98
98
.. nextslide::
99
99
@@ -235,6 +235,32 @@ new tags, etc....
235
235
236
236
See ``test_html_output8.html``
237
237
238
+
Note on indentation
239
+
===================
240
+
241
+
Indentation is not stricly required for html -- html ignores most whitespace.
242
+
243
+
But it can make it much easier to read for humans, and it's a nice excercise to see how one might make it nice.
244
+
245
+
There is also more than one way to indent html -- so you have a bit of flexibility here.
246
+
247
+
So:
248
+
249
+
* You probably ``ind`` to be an optional argument to render -- so it will not indent if nothing is passed in. And that lets you write the code without indentation first if you like.
250
+
251
+
* But ultimately, you want your code to USE the ind parameter -- it is supposed to indicate how much this entire tag is already indented.
252
+
253
+
* When this one gets rendered, you don't know where it is in a potentially deeply nested hierarchy -- it could be at the top level or ten levels deep. passing ``ind`` into the render method is how this is communicated.
254
+
255
+
* You have (at least) two options for how to indicate level of indentation:
256
+
257
+
- It could be a integer indicating number of levels of indentation
258
+
- It could, more simply, be a bunch of spaces.
259
+
260
+
* You want to have the amount of spaces per indentation defined as a class attribute of the base class (the ``Element`` class). That way, you could change it in one place, and it would change everywhere an remain consistent.
Copy file name to clipboardExpand all lines: slides_sources/source/session07.rst
+47-8Lines changed: 47 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,17 @@
4
4
Object Oriented Programming
5
5
***************************
6
6
7
+
Lightning Talks today
8
+
---------------------
9
+
10
+
.. rst-class:: medium
11
+
12
+
|
13
+
|Charles E Robison
14
+
|
15
+
|Paul Vosper
16
+
|
17
+
7
18
================
8
19
Review/Questions
9
20
================
@@ -17,19 +28,47 @@ Review of Previous Class
17
28
18
29
Testing
19
30
31
+
Any questions?
20
32
33
+
Should I go over my solution(s)?
21
34
22
-
Lightning Talks today
23
-
---------------------
24
35
25
-
.. rst-class:: medium
36
+
Notes from homework:
37
+
--------------------
26
38
27
-
|
28
-
|Charles E Robison
29
-
|
30
-
|Paul Vosper
31
-
|
39
+
**chaining or...**
40
+
41
+
Consider this:
42
+
43
+
``elif selection == '3' or 'exit':``
44
+
45
+
Careful here: you want to check if selection is '3' or 'exit', but that is no quite what this means:
46
+
47
+
You want:
48
+
49
+
``(selection == '3') or (selection == 'exit')``
50
+
51
+
== has higher precedence than or, so you don't need the parentheses.
52
+
53
+
``selection == '3' or selection == 'exit'``
54
+
55
+
That feels like more typing, but that's what you have to do.
56
+
57
+
.. nextslide::
58
+
59
+
So what does the first version mean?
60
+
61
+
It would return true for '3', but would never fail. Due to operator precedence, it is:
62
+
63
+
``(selection == '3') or 'exit'``
64
+
65
+
so first it's checking if selection == '3', which will return True or False.
66
+
67
+
Then it does the or: ``True or 'exit'`` or ``False or 'exit'``
68
+
69
+
``or`` returns the first "truthy" value it finds, to it will return either True or 'exit', regardless of the value of selection. 'exit' is truthy, so this if clause will always run.
0 commit comments