Skip to content

Commit a3b4e18

Browse files
author
Anastomose
committed
Conflicts: Examples/Session06/html_render/html_render.py Examples/Session06/html_render/html_render.pyc
2 parents 006193f + 6aaaab7 commit a3b4e18

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+15115
-173
lines changed
376 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Examples/Session05/codingbat.pyc

571 Bytes
Binary file not shown.

Examples/Session06/cigar_party.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
When squirrels get together for a party, they like to have cigars.
5+
A squirrel party is successful when the number of cigars is between
6+
40 and 60, inclusive. Unless it is the weekend, in which case there
7+
is no upper bound on the number of cigars.
8+
9+
Return True if the party with the given values is successful,
10+
or False otherwise.
11+
"""
12+
13+
14+
def cigar_party(cigars, is_weekend):
15+
"""
16+
basic solution
17+
"""
18+
if ( 40 <= cigars <= 60 ) or ( cigars >= 40 and is_weekend):
19+
return True
20+
else:
21+
return False
22+
23+
24+
def cigar_party3(cigars, is_weekend):
25+
"""
26+
conditional expression
27+
"""
28+
return (cigars >= 40) if is_weekend else (cigars >= 40 and cigars <= 60)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
Python class example.
5+
"""
6+
7+
8+
# The start of it all:
9+
# Fill it all in here.
10+
class Element(object):
11+
12+
def __init__(self, content=None):
13+
pass
14+
def append(self, new_content):
15+
pass
16+
def render(self, file_out, ind=""):
17+
file_out.write("just something as a place holder...")

Examples/Session06/html_render/run_html_render.py

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
Uncomment the steps as you add to your rendering.
77
88
"""
9-
from io import open, StringIO
9+
from cStringIO import StringIO
1010

1111

1212
# importing the html_rendering code with a short name for easy typing.
1313
import html_render as hr
14-
reload(hr)
14+
reload(hr) #reloding in case you are ruuing this in iPython
15+
# -- want to make sure the latest version is used
1516

1617

1718
## writing the file out:
@@ -24,26 +25,26 @@ def render(page, filename):
2425
"""
2526

2627
f = StringIO()
27-
page.render(f, u" ")
28+
page.render(f, " ")
2829

2930
f.seek(0)
3031

3132
print f.read()
3233

3334
f.seek(0)
34-
open(filename, 'w', encoding="utf-8").write( f.read() )
35+
open(filename, 'w').write( f.read() )
3536

3637

3738
## Step 1
3839
##########
3940

4041
page = hr.Element()
4142

42-
page.append(u"Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text")
43+
page.append("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text")
4344

44-
page.append(u"And here is another piece of text -- you should be able to add any number")
45+
page.append("And here is another piece of text -- you should be able to add any number")
4546

46-
render(page, u"test_html_output1.html")
47+
render(page, "test_html_output1.html")
4748

4849
# ## Step 2
4950
# ##########
@@ -52,134 +53,134 @@ def render(page, filename):
5253

5354
# body = hr.Body()
5455

55-
# body.append(hr.P(u"Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text"))
56+
# body.append(hr.P("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text"))
5657

57-
# body.append(hr.P(u"And here is another piece of text -- you should be able to add any number"))
58+
# body.append(hr.P("And here is another piece of text -- you should be able to add any number"))
5859

5960
# page.append(body)
6061

61-
# render(page, u"test_html_output2.html")
62+
# render(page, "test_html_output2.html")
6263

6364
# # Step 3
6465
# ##########
6566

6667
# page = hr.Html()
6768

6869
# head = hr.Head()
69-
# head.append(hr.Title(u"PythonClass = Revision 1087:"))
70+
# head.append(hr.Title("PythonClass = Revision 1087:"))
7071

7172
# page.append(head)
7273

7374
# body = hr.Body()
7475

75-
# body.append(hr.P(u"Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text"))
76-
# body.append(hr.P(u"And here is another piece of text -- you should be able to add any number"))
76+
# body.append(hr.P("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text"))
77+
# body.append(hr.P("And here is another piece of text -- you should be able to add any number"))
7778

7879
# page.append(body)
7980

80-
# render(page, u"test_html_output3.html")
81+
# render(page, "test_html_output3.html")
8182

8283
# # Step 4
8384
# ##########
8485

8586
# page = hr.Html()
8687

8788
# head = hr.Head()
88-
# head.append(hr.Title(u"PythonClass = Revision 1087:"))
89+
# head.append(hr.Title("PythonClass = Revision 1087:"))
8990

9091
# page.append(head)
9192

9293
# body = hr.Body()
9394

94-
# body.append(hr.P(u"Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
95-
# style=u"text-align: center; font-style: oblique;"))
95+
# body.append(hr.P("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
96+
# style="text-align: center; font-style: oblique;"))
9697

9798
# page.append(body)
9899

99-
# render(page, u"test_html_output4.html")
100+
# render(page, "test_html_output4.html")
100101

101102
# # Step 5
102103
# #########
103104

104105
# page = hr.Html()
105106

106107
# head = hr.Head()
107-
# head.append(hr.Title(u"PythonClass = Revision 1087:"))
108+
# head.append(hr.Title("PythonClass = Revision 1087:"))
108109

109110
# page.append(head)
110111

111112
# body = hr.Body()
112113

113-
# body.append(hr.P(u"Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
114-
# style=u"text-align: center; font-style: oblique;"))
114+
# body.append(hr.P("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
115+
# style="text-align: center; font-style: oblique;"))
115116

116117
# body.append(hr.Hr())
117118

118119
# page.append(body)
119120

120-
# render(page, u"test_html_output5.html")
121+
# render(page, "test_html_output5.html")
121122

122123
# # Step 6
123124
# #########
124125

125126
# page = hr.Html()
126127

127128
# head = hr.Head()
128-
# head.append(hr.Title(u"PythonClass = Revision 1087:"))
129+
# head.append(hr.Title("PythonClass = Revision 1087:"))
129130

130131
# page.append(head)
131132

132133
# body = hr.Body()
133134

134-
# body.append(hr.P(u"Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
135-
# style=u"text-align: center; font-style: oblique;"))
135+
# body.append(hr.P("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
136+
# style="text-align: center; font-style: oblique;"))
136137

137138
# body.append(hr.Hr())
138139

139-
# body.append(u"And this is a ")
140-
# body.append( hr.A(u"http://google.com", "link") )
141-
# body.append(u"to google")
140+
# body.append("And this is a ")
141+
# body.append( hr.A("http://google.com", "link") )
142+
# body.append("to google")
142143

143144
# page.append(body)
144145

145-
# render(page, u"test_html_output6.html")
146+
# render(page, "test_html_output6.html")
146147

147148
# # Step 7
148149
# #########
149150

150151
# page = hr.Html()
151152

152153
# head = hr.Head()
153-
# head.append(hr.Title(u"PythonClass = Revision 1087:"))
154+
# head.append(hr.Title("PythonClass = Revision 1087:"))
154155

155156
# page.append(head)
156157

157158
# body = hr.Body()
158159

159-
# body.append( hr.H(2, u"PythonClass - Class 6 example") )
160+
# body.append( hr.H(2, "PythonClass - Class 6 example") )
160161

161-
# body.append(hr.P(u"Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
162-
# style=u"text-align: center; font-style: oblique;"))
162+
# body.append(hr.P("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
163+
# style="text-align: center; font-style: oblique;"))
163164

164165
# body.append(hr.Hr())
165166

166-
# list = hr.Ul(id=u"TheList", style=u"line-height:200%")
167+
# list = hr.Ul(id="TheList", style="line-height:200%")
167168

168-
# list.append( hr.Li(u"The first item in a list") )
169-
# list.append( hr.Li(u"This is the second item", style="color: red") )
169+
# list.append( hr.Li("The first item in a list") )
170+
# list.append( hr.Li("This is the second item", style="color: red") )
170171

171172
# item = hr.Li()
172-
# item.append(u"And this is a ")
173-
# item.append( hr.A(u"http://google.com", u"link") )
174-
# item.append(u"to google")
173+
# item.append("And this is a ")
174+
# item.append( hr.A("http://google.com", "link") )
175+
# item.append("to google")
175176

176177
# list.append(item)
177178

178179
# body.append(list)
179180

180181
# page.append(body)
181182

182-
# render(page, u"test_html_output7.html")
183+
# render(page, "test_html_output7.html")
183184

184185
# # Step 8
185186
# ########
@@ -188,37 +189,37 @@ def render(page, filename):
188189

189190

190191
# head = hr.Head()
191-
# head.append( hr.Meta(charset=u"UTF-8") )
192-
# head.append(hr.Title(u"PythonClass = Revision 1087:"))
192+
# head.append( hr.Meta(charset="UTF-8") )
193+
# head.append(hr.Title("PythonClass = Revision 1087:"))
193194

194195
# page.append(head)
195196

196197
# body = hr.Body()
197198

198-
# body.append( hr.H(2, u"PythonClass - Class 6 example") )
199+
# body.append( hr.H(2, "PythonClass - Class 6 example") )
199200

200-
# body.append(hr.P(u"Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
201-
# style=u"text-align: center; font-style: oblique;"))
201+
# body.append(hr.P("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
202+
# style="text-align: center; font-style: oblique;"))
202203

203204
# body.append(hr.Hr())
204205

205-
# list = hr.Ul(id=u"TheList", style=u"line-height:200%")
206+
# list = hr.Ul(id="TheList", style="line-height:200%")
206207

207-
# list.append( hr.Li(u"The first item in a list") )
208-
# list.append( hr.Li(u"This is the second item", style="color: red") )
208+
# list.append( hr.Li("The first item in a list") )
209+
# list.append( hr.Li("This is the second item", style="color: red") )
209210

210211
# item = hr.Li()
211-
# item.append(u"And this is a ")
212-
# item.append( hr.A(u"http://google.com", "link") )
213-
# item.append(u"to google")
212+
# item.append("And this is a ")
213+
# item.append( hr.A("http://google.com", "link") )
214+
# item.append("to google")
214215

215216
# list.append(item)
216217

217218
# body.append(list)
218219

219220
# page.append(body)
220221

221-
# render(page, u"test_html_output8.html")
222+
# render(page, "test_html_output8.html")
222223

223224

224225

File renamed without changes.

0 commit comments

Comments
 (0)