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

  • SEARCH
  • Home
  • 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 7990761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:06:33+00:00 2026-06-04T13:06:33+00:00

Some background: I work in a large bank and I’m trying to re-use some

  • 0

Some background: I work in a large bank and I’m trying to re-use some Python modules, which I cannot change, only import. I also don’t have the option of installing any new utilities/functions etc (running Python 2.6 on Linux).

I’ve got this at present:

In my module:

from common.databaseHelper import BacktestingDatabaseHelper

class mfReportProcess(testingResource):
    def __init__(self):
        self.db = BacktestingDatabaseHelper.fromConfig('db_name')

One of the methods called within the ‘testingResource’ class has this:

 with self.db as handler:

which falls over with this:

with self.db as handler:
AttributeError: 'BacktestingDatabaseHelper' object has no attribute '__exit__'

and, indeed, there is no __exit__ method in the ‘BacktestingDatabaseHelper’ class, a class which I cannot change.

However, this code I’m trying to re-use works perfectly well for other apps – does anyone know why I get this error and no-one else?
Is there some way of defining __exit__ locally?

Many thanks in advance.

EDITED to add:

I’ve tried to add my own class to setup DB access but can’t get it to work – added this to my module:

class myDB(BacktestingDatabaseHelper): 
    def __enter__(self): 
        self.db = fromConfig('db_name') 
    def __exit__(self): 
        self.db.close() 

and added:

self.db = myDB 

into my init attribute for my main class but I get this error:

with self.db as handler:
TypeError: unbound method __enter__() must be called with myDB instance as first argument (got nothing instead)

Any suggestions as to how to do this properly?

  • 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-04T13:06:34+00:00Added an answer on June 4, 2026 at 1:06 pm

    The error means that BacktestingDatabaseHelper is not designed to be used in a with statement. Sounds like the classes testingResource and BacktestingDatabaseHelper are not compatible with each other (perhaps your version of common.databaseHelper is out of date).

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

Sidebar

Related Questions

I am trying to use a background worker in order to retrieve a large
Background I work for a large organization which has thousands of MS Access applications
Some background: I've created a Swing application which uses the Substance LaF (Thanks again,
Some background: My job involves maintaining a large multi-threaded multi-process C++ / C# application,
Some background: I'm a jack-of-all trades, one of which is programming. I learned VB6
First some background: I'm working on an application and I'm trying to follow MVVM
Background In some sufficiently large applications, you can spend more time figuring out how
There is a div #container which contains various divs with large background images, I
I'm currently working on a large BPM project at work which uses the Global
I've created an NSOperation to do some heavy work in background but I need

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.