__repr__ = __str__
I don't know if that's a good practice.
I've seen it in a couple places, and it's pretty explicit what
it's doing.
try:
data.setdefault(
state, {}).setdefault(
county, {}).setdefault(
cls, Attendence(max_students)).accrue(enrolled)
except TooManyAttendants:
I suggest to decompress that part a little, to make it a little more
readable.
I played around with the formatting and didn't really like any of
the formatting I came up with. My other possible alternatives were:
try:
data \
.setdefault(state, {}) \
.setdefault(county, {}) \
.setdefault(cls, Attendence(max_students)) \
.accrue(enrolled)
except TooManyAttendants:
or
try:
(data
.setdefault(state, {})
.setdefault(county, {})
.setdefault(cls, Attendence(max, 0))
).accrue(enrolled)
except TooManyAttendants:
Both accentuate the setdefault() calls grouped with their
parameters, which can be helpful. Which one is "better" is a
matter of personal preference:
* no extra characters but hard to read
* backslashes, or
* an extra pair of parens
-tkc
--
http://mail.python.org/mailman/listinfo/python-list