Skip to content

Instantly share code, notes, and snippets.

@jheasly
Last active April 27, 2016 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jheasly/817c9057f81cc2be524b486bfb4facb7 to your computer and use it in GitHub Desktop.
Save jheasly/817c9057f81cc2be524b486bfb4facb7 to your computer and use it in GitHub Desktop.
mlbgame gets batting avg.
>>> from __future__ import print_function
>>> import mlbgame
>>> game = mlbgame(2016, 4, 26, home='Mariners'][0]
>>> stats = mlbgame.player_stats(game.game_id)
>>> for player in stats['home_batting']:
... print(player.name_display_first_last, player.avg)
...
Norichika Aoki 0.205
Ketel Marte 0.238
Robinson Cano 0.224
Nelson Cruz 0.274
Franklin Gutierrez 0.231
Kyle Seager 0.141
Chris Iannetta 0.222
Dae-Ho Lee 0.235
Seth Smith 0.286
Nathan Karns 0.0
>>>
# ... and here's what's available for each home team batter:
>>> dir(stats['home_batting'][0])
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a', 'ab', 'ao',
'avg', 'bb', 'bo', 'cs', 'd', 'e', 'fldg', 'h', 'hbp', 'hr', 'id', 'lob', 'name', 'name_display_first_last', 'nice_output', 'obp', 'ops',
'po', 'pos', 'r', 'rbi', 's_bb', 's_h', 's_hr', 's_r', 's_rbi', 's_so', 'sac', 'sb', 'sf', 'slg', 'so', 't']
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment