Python reads the database, always error.

Source: Internet
Author: User

In the 8.04.4 environment (in fact, I think it is not related to the environment, I have a problem with the sentence):

$ dpkg-l | Grep-i python

II Libapache2-mod-python 3.3.1-2build1 Apache 2 module that embeds python within th

II Moinmoin-common 1.5.8-5.1ubuntu2.5 Python clone of Wikiwiki-common data

II Python 2.5.2-0ubuntu1 an interactive high-level object-oriented LA

II python-apt 0.7.4ubuntu7.7 python interface to libapt-pkg

II Python-central 0.6.7ubuntu0.1 Register and build utility for Python Packag

II Python-django 0.96.1-2ubuntu2.1 A High-level python WEB framework

II python-gdbm 2.5.2-0UBUNTU2 GNU dbm database support for Python

II Python-gnupginterface 0.3.2-9ubuntu1 Python interface to GnuPG (GPG)

II Python-minimal 2.5.2-0UBUNTU1 A Minimal subset of the Python language (def

II Python-moinmoin 1.5.8-5.1ubuntu2.5 python clone of Wikiwiki-library

II python-mysqldb 1.2.2-5ubuntu1 A python interface to MySQL

II Python-support 0.7.5UBUNTU1 Automated rebuilding support for Python Modu

II python2.5 2.5.2-2ubuntu6.2 An interactive high-level object-oriented LA

II Python2.5-minimal 2.5.2-2ubuntu6.2 A Minimal subset of the Python language (ver


Wrote a small program that wants to read the name and mail that appear in the users table of their database.


cat/var/www/dbtest.py

#!/usr/bin/python


db = MySQLdb.connect (host= "localhost", user= "XXXX", passwd= "passwd****", db= "Mymanualdb")


cursor = Db.cursor ()

Cursor.execute ("Select name, mail from users")


result = Cursor.fetchall ()


For record in result:

Print record[0], "--", record[1]


But the actual always error, do not know where the problem?


$ python/var/www/dbtest.py

File "/var/www/dbtest.py", line 11

Print record[0], "--", record[1]

^

Indentationerror:expected an indented block


This article is from the "Windmill in the Wilderness" blog, please make sure to keep this source http://moorwindmill.blog.51cto.com/2272071/1411806

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.