0

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?

Nimitz14
  • 2,138
  • 5
  • 23
  • 39
  • When you manually paste the code, do you paste the whole function? Or just the code inside? – Anand S Kumar Aug 05 '15 at 01:31
  • possible duplicate of [What does \`if \_\_name\_\_ == "\_\_main\_\_":\` do?](http://stackoverflow.com/questions/419163/what-does-if-name-main-do) – Celeo Aug 05 '15 at 01:33
  • as for IDEs, there are some. I remember reading about a python extension for eclipse. – Dleep Aug 05 '15 at 01:38

1 Answers1

1

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()
Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176