tag.get() is inconsistent
Bug #1678589 reported by
Fake Name
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Beautiful Soup |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
Basically, tag.get(<string>) is annoying to use.
If you call tag.get('class'), you get a list of attributes.
However, in all other cases, tag.get(
This means, if you're ever dealing with a context where you can be trying to get variable tag attributes, you need to do a bunch of messy isinstance() cruft on the return value of tag.get().
It's probably too late to change, but tag.get() should either *always* return a list, or *always* return a string (and leave splitting the string into a list to the user).
Moving forward, I'd suggest implementing such behaviour as a new function, and depreciating the current tag.get().
Changed in beautifulsoup: | |
status: | Fix Committed → Fix Released |
To post a comment you must log in.
I sympathize with what you're saying but I'm not going to change the behavior of Tag.get(). There are a lot of things you might do with attributes and the simplest way to handle it overall is to model what actually goes on in an HTML document: some attributes, like class and rel, have a list of values, and others can only have one value.
In revision 445 I've added a convenience method called Tag.get_ attribute_ text, which will automatically join the values of multi-valued attributes into a single string, similar to how Tag.get_text joins the strings found inside a tag into a single string.