Code Comments

Code Comments

Tips and short tutorials on various programming technologies

Code Comments RSS Feed
 
 
 
 

Archive for Reflection

Dynamically Invoke a Function in R

One way the R programming language has been described is that it is a functional programming language. Whether it would be called this by purists, I don’t know. But part of what this means is that all functions are treated as objects. So you can pass functions around very easily. This might sound strange, but [...] Read more »

How to List All Methods in a Python Object

Suppose you have an object in Python that you retrieved from a third-party library, but you don’t have access to the source code or to very good documentation. Believe me, it happens (and did to me today). You can use a simple built-in method in Python to find out which methods are exposed by a [...] Read more »

How to Invoke a Method Dynamically in Python (Reflection)

Sometimes you want to be able to invoke a method dynamically rather than calling it explicitly. Or in other words, let’s say you have a bunch of methods, and you have a string object telling you which method to execute, but rather than doing a bunch of if statements you want to be able to [...] Read more »