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

Example 6-1, Exception: Invalid field name: Company! #41

Closed jeffhoek closed 11 years ago

jeffhoek commented 11 years ago

Just did a fresh clone on MacOS X 10.8.2 (Mountain Lion) and hitting problems in example 6-1, linkedin__analyze_companies.py: Exception: Invalid field name: Company!

See my fix below... I am running python2.7 within virtualenv and have prettytable==0.6.1. here's the stack trace:

Traceback (most recent call last): File "/Applications/eclipse/plugins/org.python.pydev_2.7.1.2012100913/pysrc/pydevd.py", line 1397, in debugger.run(setup['file'], None, None) File "/Applications/eclipse/plugins/org.python.pydev_2.7.1.2012100913/pysrc/pydevd.py", line 1090, in run pydev_imports.execfile(file, globals, locals) #execute the script File "/Users/jeff/Documents/workspace/Mining-the-Social-Web/python_code/linkedin__analyze_companies.py", line 23, in pt = PrettyTable(fields=['Company', 'Freq']) File "/Users/jeff/.virtualenvs/kitsink/lib/python2.7/site-packages/prettytable.py", line 125, in init self._validate_option(option, kwargs[option]) File "/Users/jeff/.virtualenvs/kitsink/lib/python2.7/site-packages/prettytable.py", line 210, in _validate_option self._validate_all_field_names(option, val) File "/Users/jeff/.virtualenvs/kitsink/lib/python2.7/site-packages/prettytable.py", line 285, in _validate_all_field_names self._validate_field_name(name, x) File "/Users/jeff/.virtualenvs/kitsink/lib/python2.7/site-packages/prettytable.py", line 280, in _validate_field_name raise Exception("Invalid field name: %s!" % val) Exception: Invalid field name: Company!

I found the following 3 changes on lines 23-28 were necessary to make this module work:

23: pt = PrettyTable(['Company', 'Freq'])

25: pt.align['Company'] = 'l'

28: print(pt)