[Python-Dev] n.numbits: method or property?

Mark Dickinson dickinsm at gmail.com
Wed Nov 12 01:16:30 CET 2008

As Victor Stinner mentioned in a recent thread, there's a patch in
the works to add a numbits ... um ... gadget to integers, returning
the number of bits needed to represent the integer (or more
precisely, the ceiling of the log to base 2 of the integer).  See


Question for python-dev: if numbits were to be added, should it
be a property or a method? (Or something else entirely?)

More generally, what are the guidelines for determining
when it's appropriate to make something a property rather
than a method?

In favour of numbits being a (read-only, of course) property:

  - it looks nicer that way
  - it's a fast O(1) method, so is comparable to an attribute access
    in terms of efficiency
  - it can reasonably be thought of as a fundamental property of
    a binary integer
  - there are precedents, as Raymond points out in the issue
    discussion:  e.g. z.real, z.imag



More information about the Python-Dev mailing list