item[87] not pulling through

52 views
Skip to first unread message

Ian Noble

unread,
Nov 28, 2015, 9:04:32 AM11/28/15
to Python dBase
Hi Ethan and all, it's me again!

I have the following code that doesn't seem to be able to find column 87 information when I append it:

import os
import dbf


def find_folder():

target_dir = r'C:\Users\Ian\Documents\NBA Live 06\saves'

directory_list = []

# Find most recently edited directory.
for d in os.listdir(target_dir):
bd = os.path.join(target_dir, d)
if os.path.isdir(bd): 
directory_list.append(bd)
latest_subdir = max((os.path.getmtime(f),f) for f in directory_list)[1]
location = (latest_subdir + '\\' + 'teams.dbf')

t = dbf.Table(location)
return t

def pull_info():
table = find_folder()
info = []
with table:
index = table.create_index (lambda rec: (rec.teamnum))
x = 0
for x in range(30):
matches = index.search (match= (x,), partial=True)
for item in matches:
info.append( [item[3], item[2], item[87]] )
x = x + 1
print (info)

def main():

pull_info()


main()


item[87] should contain numbers, but they all come out as zero!

I have attached my database, teams.dbf, for your reference.

Thanks in advance,

Ian
teams.dbf

Adrian Klaver

unread,
Nov 28, 2015, 9:30:20 AM11/28/15
to python...@googlegroups.com
Works for me:

In [14]: info
Out[14]:
[[u'Atlanta ', u'Hawks ', 15],
[u'Boston ', u'Celtics ', 12],
[u'Charlotte ', u'Hornets ', 19],
[u'Chicago ', u'Bulls ', 24],
[u'Cleveland ', u'Cavaliers ', 10],
[u'Dallas ', u'Mavericks ', 30],
[u'Denver ', u'Nuggets ', 25],
[u'Detroit ', u'Pistons ', 22],
[u'Golden State ', u'Warriors ', 33],
[u'Houston ', u'Rockets ', 20],
[u'Indiana ', u'Pacers ', 24],
[u'LA Clippers ', u'Clippers ', 25],
[u'LA Lakers ', u'Lakers ', 22],
[u'Memphis ', u'Grizzlies ', 5],
[u'Miami ', u'Heat ', 30],
[u'Milwaukee ', u'Bucks ', 29],
[u'Minnesota ', u'Timberwolves ', 23],
[u'Brooklyn ', u'Nets ', 21],
[u'New Orleans ', u'Pelicans ', 14],
[u'New York ', u'Knicks ', 12],
[u'Orlando ', u'Magic ', 12],
[u'Philadelphia ', u'76ers ', 19],
[u'Phoenix ', u'Suns ', 19],
[u'Portland ', u'Trail Blazers ', 24],
[u'Sacramento ', u'Kings ', 24],
[u'San Antonio ', u'Spurs ', 18],
[u'Oklahoma City ', u'Thunder ', 29],
[u'Toronto ', u'Raptors ', 21],
[u'Utah ', u'Jazz ', 15],
[u'Washington ', u'Wizards ', 15]]


Are you sure your find_folder() is grabbing the correct file on your system?

>
> Thanks in advance,
>
> Ian
>
> --
>
> ---
> You received this message because you are subscribed to the Google
> Groups "Python dBase" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to python-dbase...@googlegroups.com
> <mailto:python-dbase...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


--
Adrian Klaver
adrian...@aklaver.com

Ian Noble

unread,
Nov 28, 2015, 11:59:47 AM11/28/15
to Python dBase
Oh dear how embarrassing, yes that was the problem! :) 

Ethan Furman

unread,
Nov 28, 2015, 1:34:36 PM11/28/15
to python...@googlegroups.com
On 11/28/2015 08:59 AM, Ian Noble wrote:

> Oh dear how embarrassing, yes that was the problem! :)

The one nice thing about embarrassing mistakes is they are easy to fix. :)

--
~Ethan~
Reply all
Reply to author
Forward
0 new messages