Reputation: 12743
I do want to process a command with an argument specified by the user. I thought about:
self.urlRegexFunc = "endswith"
self.urlRegex = ".mp3"
exec('b = attr[1].%s("%s")' % (self.urlRegexFunc, self.urlRegex)) # attr[1] is string
if b:
pass # Do Something
But I get:
SyntaxError: unqualified exec is not allowed in function 'start_a' it contains a nested function with free variables
What can I do?
Upvotes: 2
Views: 130