I am new to python. I have a few questions coming from an armature!
Lawrence D’Oliveiro
lawrencedo99 at gmail.com
Wed Aug 17 22:55:02 EDT 2016
On Thursday, August 18, 2016 at 12:55:33 PM UTC+12, Terry Reedy wrote:
>
> On 8/17/2016 7:13 PM, Lawrence D’Oliveiro wrote:
>
>> On Thursday, August 18, 2016 at 8:25:37 AM UTC+12, Terry Reedy wrote:
>>>
>>> for section_name, line_number in text.parser.toc:
>>> def goto(line=line_number):
>>> text.yview(line)
>>> drop.add_command(label=section_name, command=goto)
>>
>> You don’t think of that as having its own bit of subtle nastiness?
>
> No, you will have to be explicit.
That’s not my idea of being “explicit” at all. I hit a similar issue here <https://github.com/ldo/harfpy>. My solution took this sort of form:
...
#end Face
def def_face_props(celf) :
# get/set index, upem and glyph_count all have the same form:
# all these properties are unsigned integers.
def def_face_prop(propname) :
# need separate inner function so each method gets
# correct values for hb_getter and hb_setter
hb_getter = "hb_face_get_%s" % propname
hb_setter = "hb_face_set_%s" % propname
def getter(self) :
return \
getattr(hb, hb_getter)(self._hbobj)
#end getter
def setter(self, newval) :
getattr(hb, hb_setter)(self._hbobj, newval)
#end setter
getter.__name__ = propname
getter.__doc__ = "the %s property." % propname
setter.__name__ = propname
setter.__doc__ = "sets the %s property." % propname
propmethod = property(getter)
propmethod = propmethod.setter(setter)
setattr(celf, propname, propmethod)
#end def_face_prop
#begin def_face_props
for propname in ("index", "upem", "glyph_count") :
def_face_prop(propname)
#end for
#end def_face_props
def_face_props(Face)
del def_face_props
More information about the Python-list
mailing list