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 4259332
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:46:13+00:00 2026-05-21T05:46:13+00:00

from the interpreter i can issue >>> from MySQLdb just fine. so, I’m assuming

  • 0

from the interpreter i can issue >>> from MySQLdb just fine. so, I’m assuming the module did actually load. My source looks as follows:

from Tkinter import *
from MySQLdb import *
“””
Inventory control for Affordable Towing

Functions:
connection() – Controls database connection
delete() – Remove item from database
edit() – Edit item’s attributes in database
lookup() – Lookup an item
new() – Add a new item to database
receive() – Increase quantity of item in database
remove() – Decrease quantity of item in database
report() – Display inventory activity
transfer() – Remove item from one location, receive item in another

“””
def control():
….dbInfo = { ‘username’:’livetaor_atowtw’, ‘password’:’spam’, \
….’server’:’eggs.com’, ‘base’:’livetaor_towing’, ‘table’:’inventory’ }
….def testConnection():
……..sql = MySQLdb.connect(user=dbInfo[username], passwd=dbInfo[password], \
……..host=dbInfo[server], db=dbInfo[base])
……..MySQLdb.mysql_info(sql)

….testConnection()

control()

this gives me:

brad@brads-debian:~/python/towing/inventory$ python inventory.py
Traceback (most recent call last):
..File “inventory.py”, line 53, in
….control()
..File “inventory.py”, line 26, in control
….testConnection()
..File “inventory.py”, line 22, in testConnection
….sql = MySQLdb.connect(user=dbInfo[username], passwd=dbInfo[password], \
NameError: global name ‘MySQLdb’ is not defined

1) where am I going wrong?
2) any other gotcha’s that you folks see?
3) any advice on how to check for a valid connection to the database, (not just the server)?

  • 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-05-21T05:46:13+00:00Added an answer on May 21, 2026 at 5:46 am

    This is due to the way you’re importing the module and then referencing it.

    Change:

    from MySQLdb import *
    

    to

    import MySQLdb
    

    if you plan on referencing it the fashion that you are.

    Anyway, here’s how these statements and functions work:

    From: http://effbot.org/zone/import-confusion.htm

    import X imports the module X, and creates a reference to that module in the current namespace. Or in other words, after you’ve run this statement, you can use X.name to refer to things defined in module X.

    from X import * imports the module X, and creates references in the current namespace to all public objects defined by that module (that is, everything that doesn’t have a name starting with “_”). Or in other words, after you’ve run this statement, you can simply use a plain name to refer to things defined in module X. But X itself is not defined, so X.name doesn’t work. And if name was already defined, it is replaced by the new version. And if name in X is changed to point to some other object, your module won’t notice.

    from X import a, b, c imports the module X, and creates references in the current namespace to the given objects. Or in other words, you can now use a and b and c in your program.

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

Sidebar

Related Questions

Is it possible to capture Python interpreter's output from a Python script? Is it
From what I can gather, there are three categories: Never use GET and use
The issue I'm having is my wsgi file can't import the wsgi handlers properly.
If all tables I want to delete from have the column gamer_id can i
From a web developer point of view, what changes are expected in the development
From a desktop application developer point of view, is there any difference between developing
From what I've read, VS 2008 SP1 and Team Foundation Server SP1 packages are
From time to time I see an enum like the following: [Flags] public enum
From what information I could find, they both solve the same problems - more
From the Immediate Window in Visual Studio: > Path.Combine(@C:\x, y) C:\\x\\y > Path.Combine(@C:\x, @\y)

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.