Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8109905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:34:07+00:00 2026-06-06T01:34:07+00:00

Fair warning: I’m a big time noob. Please handle with kid gloves. Details: Python

  • 0

Fair warning: I’m a big time noob. Please handle with kid gloves.

Details:

  • Python 3.2
  • MySQL 5.5
  • Tornado webframe installed
  • pymysql installed
  • Windows 7

Problem:
I’m following the Tornado documentation on connecting to a mysql database here. I only want to connect to localhost, but I’m getting the following error message:

Traceback (most recent call last):
  File "C:\Python32\DIP3\tornado-test.py", line 5, in <module>
    class Connection(localhost,re_project, user=root, password=mypassword, max_idle_time=25200):
NameError: name 'localhost' is not defined

This is the code I’m trying to run:

import tornado.ioloop
import tornado.web
import pymysql

class Connection(localhost,re_project, user=root, password=mypassword, max_idle_time=25200):
    db = database.Connection("localhost", "re_project")
    for Bogota in db.query("SELECT * FROM cities_copy"):
        print(Bogota.title)

MySQL is currently running when I execute the code, so I don’t think that should be a problem. What else could I be doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:34:09+00:00Added an answer on June 6, 2026 at 1:34 am

    Okay, I think I understand the problem. In the documentation, the line class tornado.database.Connection(host, database, user=None, password=None, max_idle_time=25200) is part of the documentation and is not meant to be copy/pasted. That describes how to do the db = database.Connection bit.

    The green code sample lines should work on their own, as long as 1) the tornado.database module is imported and 2) the db = line is adjusted to pass values appropriate for your database to the Connection method.

    So:

    from tornado import database  # you can use "import tornado.database" here, but then
                                  # you will have to use "tornado.database.Connection()"
                                  # instead of "database.Connection()"
    
    db = database.Connection("localhost", "re_project", user="root", password="mypassword")
    for bogota in db.query("SELECT * FROM cities_copy"):  # I changed "bogota" to lower-case because the convention in Python is for only classes, not objects, to have upper-case names.
        print(bogota.title)
    

    I haven’t tested this because I do not have Python 3.2 installed, so let me know if it doesn’t work and I’ll try to adjust.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've spent a fair bit of time with PHP & Python frameworks and recently
Fair warning: I'm a complete noob to android development I have a Galaxy Tab
I've done a fair bit of mysql php programming but am pretty new to
First, fair warning: I am a complete newbie with C# and WPF. I have
I have a fair bit of experience with PHP frameworks and Python for scripting
Fair warning: I am no expert, but I did manage to get this far.
I've spend a fair amount of time on website optimization (YSlow, Google's Page Speed,
I just spent a fair amount of time selecting the files and directories I
I have a fair number of Python scripts that contain reusable code that are
Fair warning: The setup for this question is long, so be patient and stay

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.