Search code examples
pythonhttplib2

Not understanding what's going on with my python code and httplib2 package


I seem to be getting different results when running my script normally or entering it in my cmd.

Here's the full code:

import httplib2, re

def search_for_Title(content):

    searchBounds = re.compile('title(.{1,100})title')

    Title = re.findall(searchBounds,content)

    return Title

def main():

    url = "http://www.nytimes.com/services/xml/rss/index.html"

    h = httplib2.Http('.cache')
    content = h.request(url)

    print(content)

    print(findTitle(str(content)))

I get nothing printed when running this.

The weird thing is, if I manually paste it into the cmd, I do actually get a printout for content. I do not see where else my script could be going wrong, seeing as I've tested the search_for_Title function and it works fine.

So ye... what's going on here?

PS Is there really no good IDE like Visual Studio for C++ or eclipse for Java? I feel naked without a debugger, using notepad++ at the moment. Also, what does httplib2.Http('.cache') actually do?


Solution

  • For your script to work, you need to call the function main() , you are just defining them, not calling them Example -

    import httplib2, re
    
    def search_for_Title(content):
    
        searchBounds = re.compile('title(.{1,100})title')
        Title = re.findall(searchBounds,content)
        return Title
    
    def main():
    
        url = "http://www.nytimes.com/services/xml/rss/index.html"
        h = httplib2.Http('.cache')
        content = h.request(url)
        print(content)
        print(findTitle(str(content)))
    
    main()