Thread: Newbie help

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Newbie help


    Hi, very new to python and trying to get my Raspberry Pi talking to a MySQL DB via a web form

    Can someone shed some light please on why this isn't working?
    import MySQLdb as mdb

    def index(req):
    sensitivity = req.form.getfirst('Sensitivity', '')
    threshold = req.form.getfirst('Threshold', '')

    con = mdb.connect('localhost', 'root', '', 'mydb')

    with con:

    cur = con.cursor()
    cur.execute("UPDATE camvars SET sensitivity = %s",sensitivity)
    cur.execute("UPDATE camvars SET threshold = %s",threshold)

    return


    Thanks in anticipation

    Chris
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0
    Sorted it! Seems python is very sensitive regards indentation.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    144
    Rep Power
    4
    Originally Posted by Chrisla9
    Sorted it! Seems python is very sensitive regards indentation.
    Indentation is how you delimit blocks of code in Python, unlike other languages where you use curly braces or parenthesis or somesuch. So it's not that python is 'sensitive' to indentation, it's that indentation is part of the syntax.

    For the same reason, if you post code here in the future, it's important to use [code] tags around it to preserve the indentation.

IMN logo majestic logo threadwatch logo seochat tools logo