How to type python file in cmd?
<p>I have completed a py file as follow:</p>

<pre><code>import re

file = open('/Path/text1.txt')

word = 'summer flowers'

try : 

   flag = 0

   for line in file :

       lines = line.lower()

       x=re.findall('.*'+word+'\s.*',lines)

       if len(x)&gt;0:

           flag =1

           print line

       else:

           flag = flag

   if flag == 0:

       print 'No match!'

except:

    print 'No enough arguments!'
</code></pre>

<p>I have saved above py file as test1.py. My question is that: How to type above code in the cmd line?</p>

<p>e.g. I hope to input the code:
" <strong>test1.py 'summer flowers', text1.txt</strong> " 
in the cmd to execute above code </p>

<p>where test1.py is the file name of the py file, 'summer flowers' is the key word I want to search and match in the txt file and text1.txt is the txt file name.</p>

<p>Using the <code>sys</code> module. Specifically, <a href="https://docs.python.org/2/library/sys.html#sys.argv" rel="nofollow"><code>sys.argv</code></a></p>

<p>From the docs:</p>

<blockquote>
  <p>sys.argv</p>
  
  <p>The list of command line arguments passed to a Python script. argv[0] is the script name (it is operating system dependent whether this is a full pathname or not). If the command was executed using the -c command line option to the interpreter, argv[0] is set to the string '-c'. If no script name was passed to the Python interpreter, argv[0] is the empty string.</p>
</blockquote>

python python-2.7 text-mining