storing arbitrary Python data in Tag object attributes?

21 views
Skip to first unread message

Chris Papademetrious

unread,
Jan 10, 2025, 8:54:51 AMJan 10
to beautifulsoup
Hello fellow soupers,

I would like to store Python data as Tag object attributes (not HTML attributes). For example,

tag.my_cache = {}
tag.my_cache["a"] = 1
tag.my_cache["b"] = 2

It seems like this is okay with the following caveats:
  • The attribute name cannot conflict with a name that BS4 uses internally.
  • The attribute name would prevent any "convenience child tag" referencing (which I do not use).
  • The data is not serialized to HTML.
  • The data is not duplicated by copy/clone methods.
Am I missing anything?

 - Chris

Reply all
Reply to author
Forward
0 new messages