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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:35:59+00:00 2026-05-30T16:35:59+00:00

I am about to write a function that finds a correct handler for a

  • 0

I am about to write a function that finds a correct handler for a class. To achieve it I want to use a mapping from classes to handlers. I’ve already checked that it is possible to use classes as dictionary keys, however I am not completely sure if it is the right think to do.

My main concern is, if it is guaranteed that if I have a class imported in two different modules, these two will have the same hash. But maybe there are some other aspects that I should consider.

If idea of using classes itself is wrong, then I will use classnames, but that would require me to keep them unique, so I would prefer to use classes itself.

EDIT: I have made a test:

# file: a.py
import datetime                                                                 
D = datetime.datetime 

# file: b.py
import datetime
from a import D
print hash(D) == hash(datetime.datetime)

This prints “True”, but I am still not sure if there is a way for it to be False for the same class.

  • 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-30T16:36:00+00:00Added an answer on May 30, 2026 at 4:36 pm

    It’s perfectly valid, but note that what you are doing is fake-adding a method to that class.

    Consider whether it would be better to just add appropriate methods to your classes, either in the normal way, or possibly just by guerilla-patching. (It might not be, but consider it).

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

Sidebar

Related Questions

I am about to write junit tests for a XML parsing Java class that
I have this little function function makewindows(){ child1 = window.open (about:blank); child1.document.write(<?php echo htmlspecialchars(json_encode($row2['ARTICLE_DESC']),
I'm about to write a little GUI app that will sit in the system
I'm about to write a Scala command-line application that relies on a MySQL database.
I need to write a function that can read a file, and add all
I use a cluster of about 30 machines that have all recently been reconfigured
I would like to write a JavaScript function that validates a zip code, by
I'm trying to write a function in Javascript (with jQuery, if you want): function
I want to write code in Ruby witch net::ssh that run commands one by
I am trying to write simple function that checks to see if a designer

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.