Run time call within pprint
<p>How to pass value inside pprint at run time?</p>

<pre><code>import nltk, sys
from pprint import pprint
from nltk.corpus import framenet as fn
#Word = raw_input("enter a word: ")
pprint(fn.frames(r'(?i)Medical_specialties'))
f = fn.frame(256)
f.ID
f.name
f.definition
print f
print '\b'
pprint(sorted([x for x in f.FE]))
pprint(f.frameRelations)
print
</code></pre>

<p>At run time, I need to get a word from the user and pass it to fn.frames function in place of Medical_specialties, which in turn throws a list of frames as frame ID relevant to the word. Then I can call those numbers to query further.</p>

<p>Output:</p>

<pre><code>[&lt;frame ID=256 name=Medical_specialties&gt;]
</code></pre>

<p>Although you happen to be working with the <code>nltk</code>, your question has nothing to do with it (or with <code>pprint</code>, for that matter): You need to input a string from the user, then stick <code>"(?i)"</code> in front to construct your desired regexp. </p>

<p>Since that's all you need to do, the simplest solution is this:</p>

<pre><code>word = raw_input("enter a word: ")
rexp = "(?i)" + word
pprint(fn.frames(rexp))
</code></pre>

<p>A more powerful way to put together strings is with python's <a href="https://docs.python.org/2/library/stdtypes.html#string-formatting" rel="nofollow">C-style string formatting</a>, or the newer <a href="https://docs.python.org/2/library/string.html#format-string-syntax" rel="nofollow"><code>format()</code></a> syntax. E.g., to specify word boundaries before and after the input "word", you'd do it like this (C-style syntax):</p>

<pre><code>rexp = r"(?i)\b%s\b" % word
</code></pre>

<p>You'll probably find the above links hard to digest, so try <a href="https://pyformat.info/" rel="nofollow">this exposition</a> or <a href="http://stackoverflow.com/questions/5082452/python-string-formatting-vs-format">this high-voted SO question.</a></p>

python python-2.7 function pprint