Monday, December 16, 2013

Changes 12/16/13

NSF:

  • I forgot my laptop today, so I experimented with BeautifulSoup's syntax on another computer.
  • The code I've written takes a downloaded version of a database search for "GOVT/"NATIONAL SCIENCE FOUNDATION"" and loads it into BeautifulSoup.  It then iterates through the <tbody> element with the statement for child in soup.table.tbody.children:
  • I still can't quite figure it out, however the main problem I'm having is due to python's duck typing.  I cannot figure out how to properly check if an object is of a certain type.
  • The code in question is: isinstance(child, NavigableString), and the error I get is something like: "Type NavigableString is not valid" or something like that. I could convert the type to a string and check if it equals "bs4.elements.NavigableString", but that doesn't seem like a very elegant solution, and I want to learn how to do things "the right way"

1 comment:

  1. We should sit down and have you show me what you are doing, so I'll limit my comment here to the general question you raise. To think about a problem "Pythonically", you want to ask "Does this object have this method?" rather than "Is this object this type?". What are you trying to do with the thing you are calling a "NavigableString"?

    ReplyDelete