GithubHelp home page GithubHelp logo

ssaevent hashable? about pysubs2 HOT 2 CLOSED

tkarabela avatar tkarabela commented on May 28, 2024
ssaevent hashable?

from pysubs2.

Comments (2)

tkarabela avatar tkarabela commented on May 28, 2024

Hi Mohamed,
SSAEvent is a mutable dataclass - making it hashable would require making it immutable as well, which would be a pretty big and (IMO) somewhat unintuitive change in the API.

Note that SSAEvent does implement ordering and equality - it behaves as a tuple (subtitle.start, subtitle.end). This is mainly so that you can do subs.events.sort() and such. You can also use this to look up subtitles in a list, however this only compares the start/end timestamps and not other attributes like text, which is... somewhat unintuitive:

import pysubs2

subs = pysubs2.SSAFile()
e1 = pysubs2.SSAEvent(start=0, end=10000, text="Subtitle 1")
e2 = pysubs2.SSAEvent(start=10000, end=20000, text="Subtitle 2")
subs.append(e1)
subs.append(e2)

e = pysubs2.SSAEvent(start=0, end=10000, text="Subtitle 1")
print(e in subs)  # -> True, same times
print(e in [e1, e2])  # -> True

e = pysubs2.SSAEvent(start=0, end=10000, text="Subtitle 1 (different text)")
print(e in subs)  # -> True, same times (eh)
print(e in [e1, e2])  # -> True

e = pysubs2.SSAEvent(start=0, end=15000, text="Subtitle 1")
print(e in subs)  # -> False, different time
print(e in [e1, e2])  # -> False

Can you share a bit more of your code so that it's more clear what you're trying to achieve?

from pysubs2.

emperor-limitless avatar emperor-limitless commented on May 28, 2024

So I see the problem here, Not the fault of the library, But of my code
So for some reason if I do the matching, Like this
if item in my_set:
...
It errors, But with a normal list it works.

from pysubs2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.