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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:25:25+00:00 2026-05-12T11:25:25+00:00

I have an object that is basically a Python implementation of an Oracle sequence.

  • 0

I have an object that is basically a Python implementation of an Oracle sequence. For a variety of reasons, we have to get the nextval of an Oracle sequence, count up manually when determining primary keys, then update the sequence once the records have been inserted.

So here’s the steps my object does:

  1. Construct an object, with a key_generator attribute initially set to None.
  2. Get the first value from the database, passing it to an itertools.count.
  3. Return keys from that generator using a property next_key.

I’m a little bit unsure about where to do step 2. I can think of three possibilities:

  1. Skip step 1 and do step 2 in the constructor. I find this evil because I tend to dislike doing this kind of initialization in a constructor.
  2. Make next_key get the starting key from the database the first time it is called. I find this evil because properties are typically assumed to be trivial.
  3. Make next_key into a get_next_key method. I dislike this because properties just seem more natural here.

Which is the lesser of 3 evils? I’m leaning towards #2, because only the first call to this property will result in a database query.

  • 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-12T11:25:26+00:00Added an answer on May 12, 2026 at 11:25 am

    I think your doubts come from PEP-8:

        Note 3: Avoid using properties for computationally expensive
        operations; the attribute notation makes the caller believe
        that access is (relatively) cheap.
    

    Adherence to a standard behavior is usually quite a good idea; and this would be a reason to scrap away solution #2.

    However, if you feel the interface is better with property than a method, then I would simply document that the first call is more expensive, and go with that (solution #2).
    In the end, recommendations are meant to be interpreted.

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

Sidebar

Ask A Question

Stats

  • Questions 169k
  • Answers 169k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes, you can install a shortcut to run a command… May 12, 2026 at 1:58 pm
  • Editorial Team
    Editorial Team added an answer My suggestion would be to actually create your own workflow.… May 12, 2026 at 1:58 pm
  • Editorial Team
    Editorial Team added an answer According to C++ Standard 14.7.3/2: An explicit specialization shall be… May 12, 2026 at 1:58 pm

Related Questions

I have a problem when using Jython, but I can't seem to find a
The problem is basically this, in python's gobject and gtk bindings. Assume we have
Using Python's Networkx library, I created an undirected graph to represent a relationship network
We have a database library in C# that we can use like this: DatabaseConnection

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.