Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I got you right, you could simply use the built-in function <a href="http://docs.python.org/library/functions.html#dir" rel="nofollow"><code>dir()</code></a>. Example:</p> <pre><code>&gt;&gt;&gt; class Foo(object): ... def m1(self): ... pass ... def m2(self): ... pass ... &gt;&gt;&gt; dir(Foo) ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'm1', 'm2'] &gt;&gt;&gt; [m for m in dir(Foo) if '__' not in m] ['m1', 'm2'] </code></pre> <hr> <p><strong>EDIT:</strong> Your question and your comments aren't truly clear. It would help if you could edit your question mentioning your expected outcome. My best guess, reading your comment here below (<em>"I need to have this dictionary <code>{int type: method type}</code>"</em>) would be that you might want:</p> <pre><code>&gt;&gt;&gt; dict(enumerate([getattr(Foo, m) for m in dir(Foo) if '__' not in m])) {0: &lt;unbound method Foo.m1&gt;, 1: &lt;unbound method Foo.m2&gt;} </code></pre> <hr> <p><strong>EDIT2:</strong> Looking at your latest pastebins, when you write:</p> <pre><code>packet_ids_to_check_up = (0x0404, 0x0405, 0x0404, 0x0505, 0x0506) for packet_id in packet_ids_to_check_up: if packet_id in some_class_obj: some_class_obj[packet_id]('Hello world') </code></pre> <p>it seems you expect to have your class acting as a dictionary. If this is the case, you should probably take a look at the <a href="http://docs.python.org/dev/library/collections.abc.html" rel="nofollow"><code>collections.abc</code></a> module, and in particular the <code>MutableMapping</code> class. From the <a href="http://docs.python.org/dev/glossary.html#term-mapping" rel="nofollow">python glossary</a>:</p> <blockquote> <p><strong>mapping</strong> - A container object that supports arbitrary key lookups and implements the methods specified in the Mapping or MutableMapping abstract base classes. Examples include dict, collections.defaultdict, collections.OrderedDict and collections.Counter.</p> </blockquote> <p>This would imply implementing the following methods:</p> <ul> <li><code>__contains__</code></li> <li><code>keys</code></li> <li><code>items</code></li> <li><code>values</code></li> <li><code>get</code></li> <li><code>__eq__</code></li> <li><code>__ne__</code></li> <li><code>pop</code></li> <li><code>popitem</code></li> <li><code>clear</code></li> <li><code>update</code></li> <li><code>setdefault</code></li> </ul> <p>However, from your code is not really self-evident why you couldn't just get away with using a simple dictionary (or eventually subclassing <code>dict</code> directly...).</p> <p>Does this help?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload