diff --git a/Compression_Lab_10.py b/Compression_Lab_10.py new file mode 100644 index 0000000..5620f50 --- /dev/null +++ b/Compression_Lab_10.py @@ -0,0 +1,21 @@ + +feast = ["lambs", "sloths", "orangutans", "breakfast cereals", "fruit bats"] + +compression = [delicacy.capitalize() for delicacy in feast] + +print(compression[0]) + +comp = [delicacy for delicacy in feast if len(delicacy) > 6] + +print (comp) + +print("length of feast: ", len(feast)) +print("length of comp: ", len(comp)) + + +list_of_tuples = [(1, 'lumberjack'), (2, 'inquisition'), (4, 'spam')] + +new_comprehension = [ skit * number for number, skit in list_of_tuples ] + +print(new_comprehension) + diff --git a/notebooks/Session09.ipynb b/notebooks/Session09.ipynb index 23660ac..b77a180 100644 --- a/notebooks/Session09.ipynb +++ b/notebooks/Session09.ipynb @@ -831,7 +831,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.1" + "version": "3.5.0" } }, "nbformat": 4, diff --git a/students/Boundb3/Session07/html_project/html_render.py b/students/Boundb3/Session07/html_project/html_render.py index e051c53..4ea95ed 100644 --- a/students/Boundb3/Session07/html_project/html_render.py +++ b/students/Boundb3/Session07/html_project/html_render.py @@ -14,15 +14,15 @@ class Element(object): #class attributes tag = "element tag" indent = " " - print("hi") + #print("hi from class element") #content = [] def __init__(self, content=None, **attributes): ###!!!could i have added the link attribute here?? + #store content self.content = [] - # add an attributes dictionary self.attributes = attributes @@ -49,7 +49,7 @@ def append(self, new_content): def render_tag(self, current_ind): # tag and then content for each class attrs = "".join([' {} ="{}"'.format(key,val) for key, val in self.attributes.items()]) - #print("this is self.attributes from render_tag: ", self.attributes) + print("this is self.attributes from render_tag: ", self.attributes) #indentation + tag + content tag_str = "{}<{}{}>".format(current_ind, self.__str__(), attrs) #print("from render_tag: current_ind is '{}' and tag strg is '{}'".format(current_ind, tag_str)) @@ -99,6 +99,10 @@ class P (Element): class Html (Element): tag = "html" print("subclass tag = : ",tag) + + def render(self, file_out, current_ind= ""): + file_out.write("\n") + super().render(file_out,current_ind = current_ind) pass class Head (Element): @@ -164,15 +168,65 @@ class Br (SelfClosingTag): tag = "br" pass -class A (Element): +class A (OneLineTag): tag = "a" + def __init__(self, link, content=None, **attributes): + #self.attributes = "href=" + #contentstr = "href=" + '"'+content+'"> ' + link + + + Element.__init__(self,content, **attributes) #!!! not quite right - needs the format: link + self.attributes["href"] = link #class guided answer - THANK you!! + #print("a's link is:", self.link) + print("a's content **** is:", self.content) + print("a's kwrgs extract of href** is:", self.attributes["href"]) + + + + def render(self, file_out, current_ind= " default indent"): + print("entering a's rendering func ") + tag_str = '{}<{}{}"{}"> '.format(current_ind, self.__str__(),"href=", self.attributes.get("href")) + file_out.write(tag_str) + + + for con in self.content: + try: + #render it + print("\t--> con in A is: " , con) + file_out.write(con) #was: stuff_str.render(file_out) + except TypeError as e: + print("hit a snag: ", e, "con is: ", con) + con.render(file_out, current_ind + self.indent ) # was: .write(str(stuff_str)) ### watch it if it is self.tag + + #write out closing tag + #was: + #stop at the closing html tag + #end_tag = "{}>".format(self.tag) + #add that tag to the end of the file object + #file_out.write(end_tag) + file_out.write(" {}>\n".format(self.tag)) - def __init__(self, content=None, link="link",**attributes): - self.attributes = "href=" - contentstr = "href=" + '"'+content+'">' + link - super().__init__(contentstr,**attributes) #!!! not quite right - needs the format: link + + #to over write the default __str__ + def __str__(self): + return self.ToString() + + def ToString(self): + return "a " + + + # def render_tag(self, current_ind): + # # tag and then content for each class + # attrs = "".join([' {} ="{}"'.format(key,val) for key, val in self.attributes.items()]) + # #print("this is self.attributes from render_tag: ", self.attributes) + # #indentation + tag + content + # tag_str = "{}<{}{}".format(current_ind, self.__str__(), attrs) #removed the extra ">" from this tag render + # #print("from render_tag: current_ind is '{}' and tag strg is '{}'".format(current_ind, tag_str)) + # print("a's tag string is",tag_str," and self.string is:", self.__str__()) + # return tag_str + #self.link = link pass @@ -192,3 +246,12 @@ def __init__(self,header,content = None,**attributes): self.header = switchdict[int(header)] self.tag = self.header super().__init__(content,**attributes) + +class Meta(SelfClosingTag): + tag = "meta" + + def __init__(self,content=None, **attributes): + #dfault for charset + if "charset" not in attributes: + attributes["charset"] = "UTF-8" + SelfClosingTag.__init__(self,content,**attributes) \ No newline at end of file diff --git a/students/Boundb3/Session07/html_project/play.py b/students/Boundb3/Session07/html_project/play.py new file mode 100644 index 0000000..5ef2b97 --- /dev/null +++ b/students/Boundb3/Session07/html_project/play.py @@ -0,0 +1 @@ +__author__ = 'Brennen' diff --git a/students/Boundb3/Session07/html_project/run_html_render.py b/students/Boundb3/Session07/html_project/run_html_render.py index 0eae206..7094190 100644 --- a/students/Boundb3/Session07/html_project/run_html_render.py +++ b/students/Boundb3/Session07/html_project/run_html_render.py @@ -130,7 +130,7 @@ def render_page(page, filename): ''' # # Step 6 # ######### - +''' page = hr.Html() head = hr.Head() @@ -152,7 +152,7 @@ def render_page(page, filename): page.append(body) render_page(page, "test_html_output6.html") - +''' # # Step 7 # ######### ''' @@ -188,43 +188,45 @@ def render_page(page, filename): page.append(body) -render_page(page, "test_html_output7.html") -''' +render_page(page, "test_html_output7a.html") + # # Step 8 # ######## +''' +page = hr.Html() -# page = hr.Html() - - -# head = hr.Head() -# head.append( hr.Meta(charset="UTF-8") ) -# head.append(hr.Title("PythonClass = Revision 1087:")) +#make and build the head +head = hr.Head() +head.append( hr.Meta(charset="UTF-8") ) +head.append(hr.Title("PythonClass = Revision 1087:")) -# page.append(head) +#tuck head into the page +page.append(head) -# body = hr.Body() +#create and build the body +body = hr.Body() -# body.append( hr.H(2, "PythonClass - Class 6 example") ) +body.append( hr.H(2, "PythonClass - Class 6 example") ) -# 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", -# style="text-align: center; font-style: oblique;")) +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", + style="text-align: center; font-style: oblique;")) -# body.append(hr.Hr()) +body.append(hr.Hr()) -# list = hr.Ul(id="TheList", style="line-height:200%") +list = hr.Ul(id="TheList", style="line-height:200%") -# list.append( hr.Li("The first item in a list") ) -# list.append( hr.Li("This is the second item", style="color: red") ) +list.append( hr.Li("The first item in a list") ) +list.append( hr.Li("This is the second item", style="color: red") ) -# item = hr.Li() -# item.append("And this is a ") -# item.append( hr.A("http://google.com", "link") ) -# item.append("to google") +item = hr.Li() +item.append("And this is a ") +item.append( hr.A("http://google.com", "link") ) +item.append("to google") -# list.append(item) +list.append(item) -# body.append(list) +body.append(list) -# page.append(body) +page.append(body) -# render_page(page, "test_html_output8.html") +render_page(page, "test_html_output8.html") diff --git a/students/Boundb3/Session07/html_project/test_html_output6.html b/students/Boundb3/Session07/html_project/test_html_output6.html index 2ef6bd2..b9f7657 100644 --- a/students/Boundb3/Session07/html_project/test_html_output6.html +++ b/students/Boundb3/Session07/html_project/test_html_output6.html @@ -8,9 +8,7 @@