Importing dictionaries into python script?
<p>So i am creating a very basic text based game, however i want the answers the program gives to be relatively correct in response to different inputs. Instead of having to tell the program to write a specific thing for each different answer, i want to be able to import a dictionary of types into the script and have keywords for the different groups of words (like negative and positive connotations). Is this possible? Everything i have read hasn't really answered my question or done what i wanted...</p>

<p>my mock up scripts below:</p>

<p>Diction included:</p>

<pre><code>a=raw_input("Are you well?")
if a=='yes':
    print("Good to hear.")
elif a=='yep":
     print("Good to hear!")  

 #I don't want to put it all in manually or use 'or'
elif a=='no':
    print("That's not good!")
elif a=='nope':
    print("That's not good!")
else:
    print("Oh.")
</code></pre>

<p>with dictionary:</p>

<h1>mydiction.py</h1>

<pre><code>NegConns=('no','nope','never','No','Nope') 
#'no' etc. is what the user inputs, NegConns is the keyword
PosConns=('yes','sure','okay','fine','good')
</code></pre>

<h1>testmod.py</h1>

<pre><code>import mydiction
question=raw_input("How are you?")
if question== NegConns:
    print("That's not good.")
elif question==PosConns:
    print("Good to hear.")
else:
    print("oh.")
</code></pre>

<p>So basically if the input is negative the program is sympathetic, if the input is positive the program congratulates. I'm not sure if this is possible for exactly what i'm wanting or if i'm going about this the wrong way, and i can't seem to find help so i'm putting it out there... Thanks in advance.</p>

<p>Let's say your directory structure is as:</p>

<pre><code>--\my_project    # Your directory containing the files
    -| mydiction.py
    -| testmod.py
</code></pre>

<p>Add a <code>__init__.py</code> in <em>my_project</em> directory to make it as python <a href="https://docs.python.org/2/tutorial/modules.html" rel="nofollow">module</a>. Now your project structure will be like:</p>

<pre><code>--\my_project   
    -| __init__.py
    -| mydiction.py
    -| testmod.py
</code></pre>

<p>Now in order to <code>import</code> from <em>mydiction.py</em> to <em>testmod.py</em>, you have to mention in your <em>testmod.py</em> as:</p>

<pre><code>from mydiction import NegConns, PosConns
</code></pre>

python python-2.7