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?

Not really sure what exactly you're trying to do...

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.

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)

commented: obviously +4

you should use getattr(random, name)

Thanks, thats what i was looking for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.