title: Executing modules as scripts
body: <p>I am learn python now, and today, i met a problem
  in 
  <a href="http://docs.python.org/release/2.5.4/tut/node8.html" rel="nofollow noreferrer">http://docs.python.org/release/2.5.4/tut/node8.html</a></p>
  
  <blockquote>
    <p><strong>6.1.1 Executing modules as scripts</strong></p>
    
    <p>When you run a Python module with</p>
    
    <p><code>python fibo.py &lt;arguments&gt;</code> </p>
    
    <p>the code in the module will be executed, just as if you imported it, but with the
    __name__ set to "__main__". That means that by adding this code at the end of
    your module:</p>
  </blockquote>
  
  <pre><code>if __name__ == "__main__":
      import sys`
      fib(int(sys.argv[1]))
  </code></pre>
  
  <blockquote>
    <p>you can make the file usable as a script as well as
    an importable module, because the code
    that parses the command line only runs
    if the module is executed as the
    "main" file:</p>
    
    <p><code>$ python fibo.py 50 1 1 2 3 5 8 13 21</code>
    <code>34</code></p>
  </blockquote>
  
  <p>but when i do this in shell, i got</p>
  
  <pre><code>File "&lt;input&gt;", line 1
  python fibo.py 222
  SyntaxError: invalid syntax
  </code></pre>
  
  <p>how to execute script correctly?</p>
  
  <p>fibo.py is</p>
  
  <pre><code>def fib(n):
      a,b=0,1
      while b&lt;n:
          print b,
          a,b = b,a+b
  
  
  def fib2(n):
      result=[]
      a,b=0,1
      while b&lt;n:
          result.append(b)
          a,b=b,a+b
      return result
  
  if __name__ =="__main__":
      import sys
      fib(int(sys.argv[1]))
  </code></pre>