Question:
Python: How to prompt the user to specify the file in which you want to import?
jiyda
2011-10-07 07:34:36 UTC
I have an autograder and the first line is
from aFileName import *
I did this:
nameOfHWK = raw_input('Name Of HWK')
from nameOfHWK import *

but it tells me there is no such file although there is :
Traceback (most recent call last):
File "C:\Documents and Settings\mnabilmu\My Documents\Python TA\Homework4\py files\hw3Autograder.py", line 2, in
from nameOfHWK import *
ImportError: No module named nameOfHWK
Three answers:
ChaosGrimm
2011-10-07 09:50:13 UTC
There is not a way to do what you want to do and for a couple of reasons. First, when importing, you cant import a string, which is what you program is currently trying to do. Second, any functions in a program that use particular modules will need those modules to be imported before-hand, or you get an error about xyz not being defined.



There are a couple of options you have instead. You could just type:

----

from import *

----

in the shell. Afterwards, you will be able to call your functions from the file you imported.



Another possibility is to just import all your files at once:

----

import file1, file2, file3

# or from file1, file2, file3 import *

----
2016-12-05 02:42:22 UTC
actual each physique knows of that IPL is a center of experience fixing and corruption. So there should not be any marvel by potential of recent spot fixing scandal and Sreesanth or 2 different cricketers are actually not remoted case. what's going to you assert a pair of massive no ball by potential of RP Singh or 3 catches dropped by potential of Pollord in a row. Why, even in the day previous to this's experience between Rajasthan and Hyderabad, gamers of Rajasthan did not decide for run out allure in a sparkling run out. IPL is all approximately vulgar funds. We aim audience have our on a daily basis fix of cricket-leisure. not purely there is spot fixing yet in addition fits are scripted and it somewhat is pre desperate which communities are going to play off around and which team is going to win the trophy.
amour
2017-03-03 10:28:06 UTC
all people knows that IPL is a center of adventure fixing and corruption. So there should not be any marvel by using recent spot fixing scandal and Sreesanth or 2 different cricketers are no longer remoted case. what's going to you're saying some enormous no ball by using RP Singh or 3 catches dropped by using Pollord in a row. Why, even in the day basically before this's adventure between Rajasthan and Hyderabad, gamers of Rajasthan did no longer decide for run out attraction in a clean run out. IPL is all approximately vulgar funds. We objective marketplace have our on a daily basis restoration of cricket-leisure. no longer basically there is spot fixing yet in addition fits are scripted and it extremely is pre desperate which communities are going to play off around and which group is going to win the trophy.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...