Question from a "java background" developer

Mats Wichmann mats at wichmann.us
Tue Sep 22 08:59:25 EDT 2020


On 9/22/20 3:25 AM, Chris Angelico wrote:
> On Tue, Sep 22, 2020 at 7:15 PM Agnese Camellini
> <agnese.camellini at gmail.com> wrote:
>>
>> Hello to everyone, I have a question. I come from a Java background and I
>> would like to develop in python but i'm wondering: is there anything, in
>> python, like Java "reflection"?
>> I mean do i have a keyword to obtain all the methods and the attributes of
>> a class in python?
> 
> Yes - introspection can be done by looking at a class's dictionary.
> Check out the dir() function to start exploring!

Without knowing any specifics of what you're looking for you can examine
and modifiy object attributes. Python's dynamic nature makes the
modifying part easy (sometimes I think *too* easy :) ).  Along with
dir(), other functions to read a bit on:

type, isinstance, callable, setattr, getattr as well as the attribute
__dict__.






More information about the Python-list mailing list