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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:14:29+00:00 2026-06-12T10:14:29+00:00

I am new to Python and can’t seem to figure out why the .getRow

  • 0

I am new to Python and can’t seem to figure out why the .getRow method doesn’t run. I created a DBMain class in dbMain.py and I am using pyTest.py to create the DBMain object to run getRow. When I run the debugger in Eclipse and DBMain’s constructor does run but but when the getRow method is call nothing happens.

pyTest.py

import dbMain

def main():
    db = dbMain.DbMain()
    db.getRow()

if __name__ == '__main__':
    main()

dbMain.py

#@PydevCodeAnalysisIgnore
import pyodbc
class DbMain(object):
    cncx = ''
    def __init__(self):
        cnxn = pyodbc.connect(driver='{SQL Server}', 
                              server='server', 
                              database='database', 
                              uid='name', 
                              pwd='pwd')

    def getRow(): 
        cursor = cnxn.cursor()
        cursor.execute("select user_id, user_name from users")
        row = cursor.fetchone()
        return row
  • 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-12T10:14:30+00:00Added an answer on June 12, 2026 at 10:14 am
    1. You do not return anything from getRow. Maybe you want to include something like

      ...
      return row
      
    2. Your getRow() method is not bound to the class. The signature for an instance method should look something like getRow(self) – the first parameter is the instance, which is received explicitly (but passed implicitly, when you call someinstance.method()).

    To have something functional, you maybe should alter your dbMain to something like this:

    #@PydevCodeAnalysisIgnore
    import pyodbc
    class DbMain(object):
        def __init__(self):
            # make cnxn an attribute of the instance
            self.cnxn = pyodbc.connect(driver='{SQL Server}', server='server', 
                database='database', uid='name', pwd='pwd')
    
        # receive `self` explicitly
        def getRow(self): 
            cursor = self.cnxn.cursor()
            cursor.execute("select user_id, user_name from users")
            row = cursor.fetchone()
            # actually return something
            return row
    

    Further reading:

    • Python: Difference between class and instance attributes
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit new to python and can't seem to figure out what I'm
I'm a bit new to python and can't figure out why this is not
Sorry for the beginner question, but I can't figure out cProfile (I'm really new
I'm new with Python and I created a method that clears the screen. Is
Forgive my ignorance, I am new to Python and I can't seem to find
Very new to python and can't understand why this isn't working. I have a
I am new to python programming..can someone suggest some way to do the following:
I'm a new Python programmer who is having a little trouble using 'self' in
I am new to python,can anybody please explain the following syntax, for i in
I just setup PortablePython on my system, so I can run python scripts from

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.