In R, the get(s)
function retrieves the value of the symbol whose name is stored in the character variable (vector) s
, e.g.
X <- 10
r <- "XVI"
s <- substr(r,1,1) ## "X"
get(s) ## 10
takes the first symbol of the Roman numeral r
and translates it to its integer equivalent.
Despite spending a while poking through R-Python dictionaries and Googling various combinations of "metaprogramming", "programming on the language", "symbol", "string", etc., I haven't come up with anything. (I am a very experienced R user and a novice Python user.)
(I know the example above is a (very!) poor way to approach the problem. I'm interested in the general answer to this question, not specifically in converting Roman numerals to integers ...)