简体   繁体   中英

How to find the eof of a Visual Foxpro dbf file in python?

So I'm opening a visual foxpro dbf file in python. I'm trying to make a statement:

    if eof(): 
       Do something
    else:
       Do something

As I recall Python 3 doesn't use Eof so is there any solution on how I know if I reached the end of the file?

Here is where I open my dbf file and my for loop loops through the dbf file but I want it where I can see if it's eof first before it loop through.

    mhvupload_table = DBF('C:\Sonichr\\mhvupload.DBF', recfactory=None,load =True,ignore_missing_memofile=True)
    for mhvupload_rec in mhvupload_table:

I don't understand what you don't understand. I don't know Python, but anyway I tried this and works exactly as I said:

from dbfread import DBF
table = DBF('C:/Program Files (x86)/Microsoft Visual FoxPro 9/Samples/Northwind/Customers.dbf')


def DoIfNotEof(object):
    print(object)

def DoIfEof():
    print("\nEnd Of File is reached. Going to sleep.")

for record in table:
    DoIfNotEof(record)
DoIfEof()

As I see, that dbfread doesn't read 100% correctly (stripping long field names) but is working anyway. Probably there is a setting or something. Try visiting DaboDev . Those guys are former VFP developers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM