title: Writing a Python script to execute with a console command
body: <p>Research is at the bottom, read before -1'ing... Thanks.</p>
  
  <p>I have to write a Python script that runs SQL queries. I made a main class and called SQLQuery. Each SQLQuery instance represents a query. The script must be structured like this:</p>
  
  <pre><code>class SQLQuery(object):
  
       def __init___(self, string_myQuery)...
  
  instance1 = SQLQuery(SQLQuery1)...
  
  instance2 = SQLQuery(SQLQuery2)...
  </code></pre>
  
  <p>As a user requirement, the instances <em>must</em> be in the same file as the class (so I can't just make each instance a main and execute that file separately), and each instance <em>must</em> be executed with Linux console commands. I can execute the entire script with a simple python SQLQuery.py but I need to execute each instance separately. The queries will be executed every day, automatically, so I don't need a terminal UI tree. It should be executed with a command similar to this:</p>
  
  <pre><code>python SQLQuery.py -inst1
  </code></pre>
  
  <p>will execute instance1.</p>
  
  <pre><code>python SQLQuery.py -inst2
  </code></pre>
  
  <p>will execute instance2.</p>
  
  <p>I have researched how to execute Python scripts with Linux commands and most of the articles are about calling commands from the Python script. However, I found <a href="http://docs.python.org/2/using/cmdline.html" rel="nofollow">this article</a> from the Python documentation. It suggests adding -m, so:</p>
  
  <pre><code>python SQLQuery.py -m inst1
  </code></pre>
  
  <p>This would let me set my main with a console command, but it doesn't work since the instances aren't modules. And since the instances <em>must</em> be in the same file as the class, I can't just import them as a module when I execute SQLQuery.py with a console command.</p>