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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:59:15+00:00 2026-05-27T04:59:15+00:00

Let’s take for example this class, which is extending MySQLDB’s connection object. class DBHandler(mysql.connections.Connection):

  • 0

Let’s take for example this class, which is extending MySQLDB’s connection object.

class DBHandler(mysql.connections.Connection):
    def __init__(self,cursor=None):
        if cursor == None:
            cursor = 'DictCursor'

            super(DBHandler,self).__init__(host = db_host,
              user = db_user,
              passwd = db_pass,
              db = db,
              cursorclass=getattr(mysql.cursors, cursor))


    def getall(self,q,params=None):
        try:
           cur = self.cursor()
           cur.execute(q,params)
           res = cur.fetchall()
           return res
         except mysql.OperationalError:
            #this is the line in question
            pass


    def execute(self,q,params):
        cur = self.cursor()
        cur.execute(q,params)
        self.commit()
        return cur.lastrowid

This thing is largely a convenience to get simpler access to common required queries.

On the line marked with the comment, is it possible in Python to recall the object constructor, even though this is a member function? I use this example to illustrate because it would effectively reestablish the connection in the event it is dropped on timeout before a query is run.

I’m aware of MySQLdb’s ping() method, this is really just a question of capability. In python, Is it possible to call a constructor from within a member function called on an instance to re-initialize that instance? Thanks!

  • 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-27T04:59:15+00:00Added an answer on May 27, 2026 at 4:59 am

    Yes, you can, since it would be preferable to extract your initialization code in another method (a def init(self):).

    This is because __init__ is not really the constructor of the object, it is more the “initializer” of your instance, the real constructor is the __new__ method, that is responsible of the instance creation.

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

Sidebar

Related Questions

Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I create an object like this: Person: NSString *name; NSString *phone; NSString
Let's take a common example how a haskell function can be called from a
Let's say that I have classes like this: public class Parent { public int
Let's say I have this MySQL table: OK.. see the type field? Type 0
Let's say we have a template class Area , which has a member variable
Let's say you have a JavaScript class like this var DepartmentFactory = function(data) {
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a
Let me preface this question by saying I use TextMate on Mac OSX for
Let's say I have this: SolutionSet(const SolutionSet &solutionSet) { this->capacity_ = solutionSet.capacity_; this->solutionsList_ =

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.