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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:10:41+00:00 2026-05-30T11:10:41+00:00

I basically want to convert a Python object into a fixed length numeric (not

  • 0

I basically want to convert a Python object into a fixed length numeric (not alphanumeric) value. One way, I’ve come up with is,

import random
x = Car(brand='toyota', model='corolla', price='10000', year=1997)
random.seed(x)

random.random()
0.13436424411240122

random.seed(x)
random.random()
0.13436424411240122

I’m wondering if there is more convenient and generic way (or library) to make this work?

  • 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-30T11:10:43+00:00Added an answer on May 30, 2026 at 11:10 am

    The way you’re now using is:

    • Prone to typo error in your Car object.
    • Fragile if you forget to call random.seed() every time.
    • Case sensitive.

    Also, if I were you, I’d like to have a little control on how my number is generated.

    The other answers have already showed to you the existence of hashlib.

    I would probably use it like this:

    class Car:
        # ...
        def __hash__(self):
            md5 = hashlib.md5()
            for i in ('brand', 'model', 'price', 'year'):
                attr = getattr(self, i)
                md5.update(str(attr).lowercase())
            return int(md5.hexdigest(), 16)
    

    Reference on the integer conversion: Convert 32-char md5 string to integer.

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

Sidebar

Related Questions

I just installed Jython 2.5.1. I want to convert my Python file into Java
I basically just want to take a 8 character ASCII value 003fc000 and convert
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
I have an SPListItemCollection. I basically want to get one of the items (randomly)
I want to convert this css behaviour into a jquery hover statement (because IE7/8
I want to convert the 5 space indentation in a python file to 4
Basically, I have a RichTextBox and I want to convert the formatted contents of
Is there any quick function that will convert: HtTp://www.ExAmPle.com/blah to http://www.example.com/blah Basically I want
I am currently using rails 3.1 and paperclip. I basically want a way so
I basically want to use link_to to link to the index method of a

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.