| | |
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 |
Tag cloud for Python
accessdenied apache application argv beginner book change code color converter dictionary dynamic edit editing enter examples excel file filename float format ftp function gui homework import inches input java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysql newb number numbers numeric output parameters parsing path phonebook port prime program programming projects py2exe pygame pyopengl pyqt python random recursion recursive redirect remote reverse scrolledtext server session simple smtp software sprite ssh statictext string strings syntax table tennis terminal text thread threading time tkinter tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable windows wordgame wxpython






