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 @@


{} And this is a - - href="http://google.com">link - + link to google diff --git a/students/Boundb3/Session07/html_project/test_html_output7.html b/students/Boundb3/Session07/html_project/test_html_output7a.html similarity index 89% rename from students/Boundb3/Session07/html_project/test_html_output7.html rename to students/Boundb3/Session07/html_project/test_html_output7a.html index fe66b13..aa8a397 100644 --- a/students/Boundb3/Session07/html_project/test_html_output7.html +++ b/students/Boundb3/Session07/html_project/test_html_output7a.html @@ -1,3 +1,4 @@ + PythonClass = Revision 1087: @@ -17,9 +18,7 @@

PythonClass - Class 6 example

  • And this is a - - href="http://google.com">, link - + link to google
  • diff --git a/students/Boundb3/Session07/html_project/test_html_output8.html b/students/Boundb3/Session07/html_project/test_html_output8.html new file mode 100644 index 0000000..3a24f0c --- /dev/null +++ b/students/Boundb3/Session07/html_project/test_html_output8.html @@ -0,0 +1,27 @@ + + + + {'charset': 'UTF-8'} + PythonClass = Revision 1087: + + +

    PythonClass - Class 6 example

    +

    + Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text +

    +
    {} + + + diff --git a/students/Boundb3/Session09/Circle _S09.py b/students/Boundb3/Session09/Circle _S09.py new file mode 100644 index 0000000..3bc31ea --- /dev/null +++ b/students/Boundb3/Session09/Circle _S09.py @@ -0,0 +1,93 @@ + + +#create a circle + +class Circle (object): + + def __init__(self,radius,*args,**kwargs): + self.radius = radius + self.diameter = radius * 2 + self._area = 3.14 * (radius * radius) + + ################################ radius + @ property + def radius(self): + return self._radius + + @ radius.setter + def radius(self,value): + + print("*****im in radius setter \t", end="") + + if value < 1: print("that is a very small circle!") + if value > 3: print("that is a good size circle!") + self._radius = value + + ################################ diameter + @ property + def diameter(self): + return self._radius * 2 + + @ diameter.setter + def diameter(self,value): + print("*****im in diameter setter") + self._radius = (value / 2) + self._diameter = value + + ################################ area + @ property + def area(self): + return self._area + + @ area.setter + def area(self,value): + print("Don't change the area - change the radius: AttributeError") + # try: + # return self._area + # except Exception as e: + # print(e) + # if e == "AttributeError": + # print(e) + # else: + # print ("some kind of error. Details: ", e) + # print("AGAIN - don't do this: change the area - change the radius: AttributeError") + # return "AttributeError" + + + def from_diameter(self,diameter_value): + radius = diameter_value /2 + radius = self.__init__(radius) + + + + + + + + + +c1 = Circle(2) +print("c1's radius is: {} and diameter is {} ".format(c1.radius, c1.diameter)) + +c2 = Circle(3) +print("c2's radius is: {} and diameter is {} ".format(c2.radius, c2.diameter)) +#print("c2's diameter: " , c2.diameter) +#print("c2's radius: " , c2.radius) + +c2.diameter = 7 +print("c2's radius is: {} and diameter is {} ".format(c2.radius, c2.diameter)) +# print("now c2's diameter: " , c2.diameter) +# print("and c2's radius: " , c2.radius) + +c1.radius = 5 +print("c1's radius is: {} and diameter is {} ".format(c1.radius, c1.diameter)) + +print("c1.area is {}".format(c1.area)) +c1.area = 14 +print("c1.area is {}".format(c1.area)) + +# c4 = Circle.from_diameter(8) +# print("c4's radius is: {} and diameter is {} ".format(c4.radius, c4.diameter)) + +cd = Circle.from_diameter(8) +print("cd's radius is: {} and diameter is ".format(cd.radius)) diff --git a/students/Boundb3/Session09/Circle_S09b.py b/students/Boundb3/Session09/Circle_S09b.py new file mode 100644 index 0000000..6367564 --- /dev/null +++ b/students/Boundb3/Session09/Circle_S09b.py @@ -0,0 +1,20 @@ +class Song(object): + + def __init__(self, lyrics): + self.lyrics = lyrics + + def sing_me_a_song(self): + for line in self.lyrics: + print(line[::1]) + +happy_bday = Song(["Happy birthday to you", + "I don't want to get sued", + "So I'll stop right there"]) + +bulls_on_parade = Song({"They rally around tha family":1, + "With pockets full of shells":2}) + +happy_bday.sing_me_a_song() + +bulls_on_parade.sing_me_a_song() +