Python Forum
Custom method to handle exceptions not working as expected
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom method to handle exceptions not working as expected
#4
I don't understand why you would use indexing with find_all(). I would expect code to iterate over the find_all() results, and an index error would not be possible.

Can you post an example of code where indexing is required? In your posted example don't see why you didn't use find() instead of find_all().

But if you did need to use find_all() you could do it like this.
if title_selector := content.findAll('h1', attrs={"itemprop": "title"})
    title = title_selector[0].text
Reply


Messages In This Thread
RE: Custom method to handle exceptions not working as expected - by deanhystad - Dec-22-2022, 07:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python trivial endgame engine is not working as expected max22 0 623 Feb-24-2024, 04:41 PM
Last Post: max22
  Simple conditional not working as expected return2sender 8 1,119 Aug-27-2023, 10:39 PM
Last Post: return2sender
  Method works as expected on host machine but not on server gradlon93 4 1,191 Jan-05-2023, 10:41 AM
Last Post: DeaD_EyE
  PiCamera - print exceptions? korenron 2 924 Dec-15-2022, 10:48 PM
Last Post: Larz60+
Exclamation My code is not working as I expected and I don't know why! Marinho 4 1,178 Oct-13-2022, 08:09 PM
Last Post: deanhystad
  Class exceptions DPaul 1 1,384 Mar-11-2022, 09:01 AM
Last Post: Gribouillis
Question Having trouble writing an Enum with a custom __new__ method stevendaprano 3 4,424 Feb-13-2022, 06:37 AM
Last Post: deanhystad
  set and sorted, not working how expected! wtr 2 1,381 Jan-07-2022, 04:53 PM
Last Post: bowlofred
  is this a good way to catch exceptions? korenron 14 4,884 Jul-05-2021, 06:20 PM
Last Post: hussaind
  Python, exceptions KingKhan248 6 3,182 Nov-15-2020, 06:54 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020