I have a line like:
str = "pwd.getpwuid(1000)"
Now, if I try eval (), that may throw an exception, because I have not imported pwd yet (or maybe not if I have).
So, I decided to write a parser that: breaks this line into "." and get the list:
lis = ["pwd", "getpwuid(1000)"]
then take lis[0]if it does not contain "("or ")", I call
importlib.import_module(lis[0])
and then again eval.
Can I do the same better?
source
share