Ry
2012-04-14 13:48:54 UTC
Hi again, been using this great software for awhile now. One thing I can't
figure out though is how to access the hash attributes of a Perl object
from within Python. For example, I have a "Pythonized" Perl subroutine
called Player() that returns an object that has an attribute 'name'
(accessed in Perl using $object->{name}). So in Python, I do 'player =
Player(0)'. How do you get the 'name' attribute?
The Perl version of the Player() subroutine was not created by me, and is
part of another library. I'm using Inline::Python from within a plugin that
is loaded into a application using that library, so I can't modify the
subroutine. I could try to create a subclass of the class returned by
Player() and add a __getattr__() subroutine to it, but that seems too
hackish. I'm trying to use Python as much as possible.
BTW, I got the subroutine by doing something like Player =
perl.eval('\&Player'). I do the same kind of thing to get other objects,
like object = perl.eval('\@array'). Is there a better way to do this?
Inline::Python does not seem to allow the use of other perlmodule functions
such as perl.callm().
Thanks,
Ryan
figure out though is how to access the hash attributes of a Perl object
from within Python. For example, I have a "Pythonized" Perl subroutine
called Player() that returns an object that has an attribute 'name'
(accessed in Perl using $object->{name}). So in Python, I do 'player =
Player(0)'. How do you get the 'name' attribute?
The Perl version of the Player() subroutine was not created by me, and is
part of another library. I'm using Inline::Python from within a plugin that
is loaded into a application using that library, so I can't modify the
subroutine. I could try to create a subclass of the class returned by
Player() and add a __getattr__() subroutine to it, but that seems too
hackish. I'm trying to use Python as much as possible.
BTW, I got the subroutine by doing something like Player =
perl.eval('\&Player'). I do the same kind of thing to get other objects,
like object = perl.eval('\@array'). Is there a better way to do this?
Inline::Python does not seem to allow the use of other perlmodule functions
such as perl.callm().
Thanks,
Ryan