I want to call built in str functions manually (in this case as randomness) without using eval
funcs = [str.lower, str.upper]
random.choice(self.funcs)("test")
or
"test".(random.choice(self.funcs))
I want to call built in str functions manually (in this case as randomness) without using eval
funcs = [str.lower, str.upper]
random.choice(self.funcs)("test")
or
"test".(random.choice(self.funcs))
You can do this
>>> funcs = [str.lower, str.upper]
>>> random.choice(funcs)('Foo')
Instead of calling a string's method, like 'Foo'.lower(), you call the str class's method, and provide your string as the instance of string that the method is called upon. Like this:
>>> str.lower('FOO')
'foo'