Results 1 to 3 of 3

Thread: [Python] Help with isinstance() on a custom type

  1. #1
    Join Date
    Jun 2007
    Beans
    1,659
    Distro
    Ubuntu

    [Python] Help with isinstance() on a custom type

    I am using BeautifulSoup and have BeautifulSoup.py in the same folder as my program.

    Running type() on a specific object I want to check against gives me this output:
    Code:
    <class 'BeautifulSoup.NavigableString'>
    How can I use isinstance on any other item to see if it is of this type?

    using isinstance(item, <class 'BeautifulSoup.NavigableString'>) doesn't work.
    Last edited by blazemore; March 1st, 2011 at 04:18 PM.

  2. #2
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    Re: [Python] Help with isinstance() on a custom type

    Code:
    isinstance(obj, BeautifulSoup.NavigableString)
    or
    Code:
    a = BeautifulSoup.NavigableString(...)
    isinstance(obj, type(a)

  3. #3
    Join Date
    Jun 2007
    Beans
    1,659
    Distro
    Ubuntu

    Re: [Python] Help with isinstance() on a custom type

    Quote Originally Posted by MadCow108 View Post
    Code:
    isinstance(obj, BeautifulSoup.NavigableString)
    or
    Code:
    a = BeautifulSoup.NavigableString(...)
    isinstance(obj, type(a)
    The first one gives me something like BeautifulSoup has no attribute NavigableString.
    I'll try the second one in a minut.e
    Thanks.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •