Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

Conversation

@Eowyn42
Copy link
Contributor

@Eowyn42 Eowyn42 commented Dec 2, 2017

Completed all steps and am rendering lovely HTML. run_html_renderer.py produces great results, tests have I believe adequate coverage of relevant items, and in general I'm very happy with this. Oh and I refactored a few things to reduce repetition. If any review happens, it would be on the test coverage of steps 4-8 tasks. Thank you.

@Eowyn42
Copy link
Contributor Author

Eowyn42 commented Dec 2, 2017

Finished the circle class, too. I included subtraction, true division, floor division, modulo and reflective operators for add/subtract. I did not like the idea of circles with negative radii so I implemented the abs() unary operator, which I then used in the subtraction and r-sub operators.

Question 1: do I really need to define a new radius and return a new circle with that radius? I wanted to just work with self, other, but odd things were happening
Question 2: there's repeated code with the reflective operators, is that avoidable?

I hope to attend office hours & during that time implement pow and other ones that make sense

Copy link
Contributor

@PythonCHB PythonCHB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks great --nice work!

newrad = self.radius - other.radius
return abs(Circle(newrad))

def __mod__(self, other):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how useful mod is for circles .. but what the heck for completeness' sake :;)

but couldn't you use the built-in mod operator: % ?

close_tag = '{}</{}>'.format(current_ind, self.tag)
out_file.write(close_tag)

def render_open_tag(self, out_file, current_ind):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great idea to pull this out to a separate method.

but I think it's a bit cleaner to have this method return the entire tag as a string, and then actually write it to the out_file in the render method. That keeps all the actual file writing in one place.

open_tag += ">"
return open_tag

def get_tag_attributes(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice!


def render(self, out_file, current_ind=""):
# Render just a tag and any attributes, ignore contents
self.render_open_tag(out_file, current_ind)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since all this doing is calling render_open_tag(), and that is overidden this this subclass, you may as well put the code in there right in here.

unless you think there are other subclasses that might use this get_open_tag method.

# Instructions said subclass from Element but we want it on one line
tag = 'a'

def __init__(self, link=None, content=None, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect! remarkably easy, isn't it?

# render just one tag and any attributes

def render(self, out_file, current_ind=""):
# Render just a tag and any attributes, ignore contents
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! but maybe you should raise an error if there are any contents -- probably in the init -- that would be better than simply ignoring it.

return Circle(newrad)

def __rtruediv__(self, factor):
# reflective division... repeats code??
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's reveresed -- is it giving the right answer? I woulndn't expect so!

but if it is repeated, you can re-use the previous definition:

def rtrudiv = truediv

pretty cool, eh?


# ---------------- UNARY ARITHMETIC OPERATORS -----------------------

def __abs__(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another one that may not make sense....

@PythonCHB PythonCHB merged commit f216a5c into UWPCE-PythonCert:master Dec 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants