How do I make a python script like answer = raw_input() if answer: BLAH import script
How do I make a python script as:
answer = raw_input() if answer: "BLAH" then import script
Well I'm开发者_C百科 new to python and really programming altogether. I got this book on python called learning python by: Mark Lutz. no where in the book have i found out how to do this but I haven't read threw the book fully I have looked everywhere and found a little help but I'm hitting so many snares in development on this simple program. Could anyone help me on this one?
>>> if raw_input("input something!:") == 'BLAH':
... import some_module.py
...
input something!:BLAH
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ImportError: No module named some_module.py
>>>
Here is a simple example of how you can set this up:
$ ls
__init__.py main_script.py simple_script.py
$ cat main_script.py
if raw_input() == "BLAH":
import simple_script
$ cat simple_script.py
print "simple_script imported"
$ echo BLAH | python main_script.py
simple_script imported
You mean something like this?
text = raw_input("import y/n: ")
if text == "y":
import random #or whatever module you want
print random.uniform(10, 20)
精彩评论