Shortest hash in python to name cache files

后端 未结 8 654
春和景丽
春和景丽 2020-12-23 22:45

What is the shortest hash (in filename-usable form, like a hexdigest) available in python? My application wants to save cache files for some objects. The objects mu

8条回答
  •  一个人的身影
    2020-12-23 23:03

    If you do have a collision, how are you going to tell that it actually happened?

    If I were you, I would use hashlib to sha1() the repr(), and then just get a limited substring of it (first 16 characters, for example).

    Unless you are talking about huge numbers of these objects, I would suggest that you just use the full hash. Then the opportunity for collision is so, so, so, so small, that you will never live to see it happen (likely).

    Also, if you are dealing with that many files, I'm guessing that your caching technique should be adjusted to accommodate it.

提交回复
热议问题