IndentationError in my python script
Question: my python version is 2.7.2, and my OS is win XP.

this is my script:

    
    
    import sqlite3
    import os
    from flask import Flask, request, session, g, redirect, url_for, \
         abort, render_template, flash
    
    DATABASE = 'C:\Python27\flaskr.db'
    DEBUG = True
    SECRET_KEY = 'development key'
    USERNAME = 'admin'
    PASSWORD = 'default'
    
    app = Flask(__name__)
    app.config.from_object(__name__)
    
    def connect_db(): return sqlie3.connect(app.config['DATABASE']  
    
    if __name__ == '__main__':
        app.run()
    

The error came up when I was running it as a module with python shell.

    
    
    if __name__ == '__main__':
        app.run()
    

Right at the “：” is the place where the idle gave the error message that
there's a invalid syntax. But I can hardly find out any syntax error.


Answer: You have missed to close one parenthesis at:

    
    
    def connect_db(): return sqlie3.connect(app.config['DATABASE'] 
    

It should be:

    
    
    def connect_db(): return sqlie3.connect(app.config['DATABASE'])
    

And the reason it goes all the way to the `:` is that Python tries to
interpret this as a [conditional
expression](http://docs.python.org/2/reference/expressions.html#conditional-
expressions):

    
    
    def connect_db(): return sqlie3.connect(app.config['DATABASE'] if __name__ == '__main__': ...
    

But because `:` cannot be a part of a valid [boolean
operation](http://docs.python.org/2/reference/expressions.html#boolean-
operations) it gives you this lovely syntax error.

