It is not a question of being pythonic or not, but is rather a question of code design. There are multiple ways to achieve what you want, and your choice mainly depends on the function contract. That said, one approach would be to accept the initializing function as the argument:
def setValue(distribution):
a = distribution(parameters)
setValue(np.random.normal)
with the use of functools.partial you can fixate parameters of the initializer if necessary
setValue(partial(np.random.normal, scale=1))
A different approach would be to have a static mapping between names and
initializers:
distribution = {
'uniform': np.random.uniform,
'normal': np.random.normal,
}
def setValue(name):
a = distribution[name](parameters)
setValue('normal')
Finally, you can always use introspection to call the method indirectly
def setValue(name):
a = getattr(np.random, name)(parameters)
setValue('uniform')
but this is a subject to code smell and also is not secure if being run in an untrusted environment.
There are other approaches as well, but they are far more complicated and, as I said, mainly depend on the code design.