How would i do this?

import random

name = random

random.name

I dont cant to use name = random.random, as name is something that could change

Im not quite sure what you are doing. But you can do something like this

import random as name
name.random()
name.randrange(1,50)
#etc

Hope that helps :P if not, could you explain what you mean a bit more in depth?

How would i do this?

import random

name = random

random.name

I can't use 'name = random.random', as name is something that could change.

No, you can't do something like that.

But you can do:

from random import *

name = random()

print (name)

But I'm afraid that's the best you're going to do.

Edited 7 Years Ago by AutoPython: n/a

thanks for the replies, but unfortunatly none of thee will work.

I am basically trying to return a function from a library if it is not in a class.

import random

class whatever(object):
    def __getattr___(self, name):
        if name not in locals():
            return random.name

thanks for the replies, but unfortunatly none of thee will work.

I am basically trying to return a function from a library if it is not in a class.

import random

class whatever(object):
    def __getattr___(self, name):
        if name not in locals():
            return random.name

you should use getattr(random, name)

Comments
obviously

you should use getattr(random, name)

Thanks, thats what i was looking for.

This article has been dead for over six months. Start a new discussion instead.