Should "print dir(cont)" list "getOwner"?

I’m just wondering, because logically every function under “cont” (cont = GameLogic.getCurrentController()) should be displayed with “print dir(cont)”, including “getOwner()”.

For some reason “getOwner()” isn’t listed. All the other stuff is there, like “getActuator()” sensor/s etc, but “getOwner()” just doesn’t show.

So does “print dir(cont)” only display some available functions, or is there some kind of a special situation with “getOwner()”?

Anyone know?

Hmm. Strange one.
It returns true on hasattr(cont,“getOwner”)
I don’t have any idea. It should be there.:confused:

Edit: It must have something to do with python’s inheritance. getOwner is an inherited method:
http://www.blender.org/documentation/pydoc_gameengine/PyDoc-Gameengine-2.34/SCA_PythonController.SCA_PythonController-class.html
So apparently, dir only lists class methods, not parent class.

Ahh, I see.

Thanks fireside.

According to the Python help file under 2.1 Built in functions :
The list is not necessarily complete

Why it wouldn’t be complete … I guess you might have to ask on a dedicated Python web site.

Mike

Hmm…Incomplete?

Well, according to firesides findings, “print dir(cont)” will list everything except inherited methods from “SCA_ILogicBrick”.

So I guess if there was a way to display those inherited methods with class methods the list would be complete. Right?

Is there a way to do that?

I’m wrong about inherited methods. I did this test:


class a:
    def get(self):
        pass

class b(a):
    def get2(self):
        pass


print dir(b)

It prints both functions.
The incomplete answer doesn’t really make sense either, since I didn’t do anything to dir and yet it listed both functions. I also tried an instance of the class, but got the same results. Maybe it has something to do with multiple inheritance, although it only shows one parent in the GameLogic specs.
Can some python guru help us out here? I’m stuck.

it’s because they just didnt write in the the PyDocs before they compiled blender… i could make it say it has destroyTheWorld() if i wanted… it’s just because nobody wrote it.

Strange… You’re correct that it is not returning getOwner(). “print dir(cont)” should also return getExecutePriority() and setExecutePriority(), both of which are also inherited from SCA_ILogicBrick. Since it is not printing any inherited methods, it is obviously an inheritance related issue. I did a quick check, and it seems that nothing in Blender’s Game Engine API returns inherited methods when you use print dir() on it. The 2.42a Python API Reference generated off of the Blender source code seems to be complete, though. I think scabootssca posted a copy that he generated somewhere around here, and somebody else posted instructions on generating it yourself.

Edit: You beat me to the post, scabootssca. So you’re saying that the dir() function reads a list included in the source and doesn’t actually search the classes themselves?

it’s because they just didnt write in the the PyDocs before they compiled blender… i could make it say it has destroyTheWorld() if i wanted… it’s just because nobody wrote it.

Apparently it’s a blender issue, then, because I didn’t write any pydocs for the example above and python returned both methods. Maybe it has something to do with them only using portions of python, like an abridged os module, etc. I wish they’d drop the dll and link up with python on the system and use all the standard libraries. Then it would be really easy to add site package modules. Most people have python on their systems and if they don’t you could just ask them to download it. Don’t know if there’s a speed difference using the dll or not. I can’t use it on linux and it seems to run fast enough. It might be the authors purposely took the base classes out of the pydocs for a faster search or something.

The reason it doesn’t work as expected, is because the python classes in blender are NOT written in python. They are written in c++. They have to be to interface with the rest of blender. It is a lot of work to build python classes in C++ so there are a lot of gaps, such as things not showing up in dir().

So yeah, don’t rely on dir(), best to use the gameengine docs. I wish there were some updated ones, the ones that are there are missing quite a few of the more recent features.

You can generate your own 2.42a Python API reference from the source code. Here is a thread that explains how to do it:

http://blenderartists.org/forum/showthread.php?t=78607

Eventually, I’d like to post the updated reference on my website.