ptwobrussell / Mining-the-Social-Web

The official online compendium for Mining the Social Web (O'Reilly, 2011)
http://bit.ly/135dHfs
Other
1.21k stars 491 forks source link

SyntaxError in Ex 1-12 and when using 'except IndexError:' #28

Closed sp00 closed 11 years ago

sp00 commented 12 years ago

Hi :)

I'm working through the examples in MTSW in example 1-12

OUT="snl_search_results.dot try:
nx.drawing.write_dot(g, OUT) except Importer, e: dot=['"%s" -> "%s" [tweet_id=%s]' % (n1, n2, g[n1][n2]['tweet_id']) \ for n1,n2 in g.edges()] f=open(OUT, 'w') f.write(strict digraph {\n%s\n}' % (';\n' .join(dot),)) f.close() ...:

File "", line 2 nx.drawing.write_dot(g, OUT)

except Importer, e: ^ SyntaxError: invalid syntax

Then I moved to a different example 2-2 import sys import urllib2 import HTMLParser from BeautifulSoup import BeautifulSoup URL=sys.argv[1]

and get the following error


IndexError Traceback (most recent call last) /Library/Frameworks/ in () ----> 1 URL=sys.argv[1]

IndexError: list index out of range

can you help please?

Thanks in advance

Lee

ptwobrussell commented 12 years ago

Regarding the syntax error in Example 1-12, it looks as though you've missed a closing quote at the very end of the line beginning with OUT

Regarding the issue with Example 2-2, you'll need to pass in a command line argument that's the URL that you want the script to read in (which is what sys.argv[1] represents), or you can redefine that line to say URL="http:// ..." and not pass in an argument.

Hope that helps.

On Jun 20, 2012, at 3:51 PM, sp00 wrote:

Hi :)

I'm working through the examples in MTSW in example 1-12

OUT="snl_search_results.dot try:
nx.drawing.write_dot(g, OUT) except Importer, e: dot=['"%s" -> "%s" [tweet_id=%s]' % (n1, n2, g[n1][n2]['tweet_id']) \ for n1,n2 in g.edges()] f=open(OUT, 'w') f.write(strict digraph {\n%s\n}' % (';\n' .join(dot),)) f.close() ...:

File "", line 2 nx.drawing.write_dot(g, OUT)

except Importer, e: ^ SyntaxError: invalid syntax

Then I moved to a different example 2-2 import sys import urllib2 import HTMLParser from BeautifulSoup import BeautifulSoup URL=sys.argv[1]

and get the following error


IndexError Traceback (most recent call last) /Library/Frameworks/ in () ----> 1 URL=sys.argv[1]

IndexError: list index out of range

can you help please?

Thanks in advance

Lee


Reply to this email directly or view it on GitHub: https://github.com/ptwobrussell/Mining-the-Social-Web/issues/28

ptwobrussell commented 11 years ago

Hopefully, this advice helped. Please re-open if you need additional help.