How to get filename from stdin
<p>I am writing a script and i am running it from the console like this</p>

<p><code>cat source_text/* | ./mapper.py</code></p>

<p>and i would like to get the filename of each file reading at the time. Source texts folder contains a bunch of text files whose filename i need to extract as well in my mapper script.</p>

<p>Is that possible? </p>

<pre><code>import sys
import re
import os


# re is for regular expressions
pattern = re.compile("[a-zA-Z][a-zA-Z0-9]*",
                     re.MULTILINE | re.DOTALL | re.IGNORECASE)


# Read pairs as lines of input from STDIN
for line in sys.stdin:
    ....
</code></pre>