| | |
calling a module from a variable?
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2009
Posts: 50
Reputation:
Solved Threads: 16
How would i do this?
I dont cant to use name = random.random, as name is something that could change
Python Syntax (Toggle Plain Text)
import random name = random random.name
I dont cant to use name = random.random, as name is something that could change
0
#2 Oct 18th, 2009
Im not quite sure what you are doing. But you can do something like this
Hope that helps
if not, could you explain what you mean a bit more in depth?
Python Syntax (Toggle Plain Text)
import random as name name.random() name.randrange(1,50) #etc
if not, could you explain what you mean a bit more in depth? Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Check out my Site | and join us on IRC | Python Specific IRC
1
#4 Oct 18th, 2009
•
•
•
•
How would i do this?
Python Syntax (Toggle Plain Text)
import random name = random random.name
I can't use 'name = random.random', as name is something that could change.
But you can do:
Python Syntax (Toggle Plain Text)
from random import * name = random() print (name)
But I'm afraid that's the best you're going to do.
Last edited by AutoPython; Oct 18th, 2009 at 11:41 am.
•
•
Join Date: Sep 2009
Posts: 50
Reputation:
Solved Threads: 16
1
#5 Oct 18th, 2009
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.
I am basically trying to return a function from a library if it is not in a class.
Python Syntax (Toggle Plain Text)
import random class whatever(object): def __getattr___(self, name): if name not in locals(): return random.name
3
#6 Oct 18th, 2009
•
•
•
•
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.
Python Syntax (Toggle Plain Text)
import random class whatever(object): def __getattr___(self, name): if name not in locals(): return random.name
getattr(random, name) ![]() |
Similar Threads
- how to Access Module variable in ToolStripMenuItem_Click Event (VB.NET)
- Calling Module in Access Database from Web Page (ASP)
- How do I pass values from a called form to a calling forms variables? (C++)
- Common Dialog (Visual Basic 4 / 5 / 6)
- help with this code of link list (C++)
- calling session variable (ASP.NET)
- new member here :) (C)
Other Threads in the Python Forum
- Previous Thread: Reversing case out of curiosity.
- Next Thread: Story Statistics (Python)
| Thread Tools | Search this Thread |
alarm assignment avogadro beginner bluetooth character cmd code customdialog cx-freeze data decimals dictionary directory dynamic error examples exe file float font format function generator getvalue gnu graphics gui halp homework http ideas import input ip itunes java leftmouse line linux list lists logging loop maze millimeter module mouse number numbers output parsing path port prime programming projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext slicenotation sqlite ssh stdout string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode urllib urllib2 variable ventrilo verify vigenere web webservice wikipedia windows wxpython xlib






