简体   繁体   中英

Unable to open database files

I am trying to use this code to open my database but I am having an error message. Here is my code:

def load_data(data_path='.', expnames=('R1','R2','R3','R4'), segments=('wait','blanking','preeject','eject'), fnpattern='AKF_E_{exp_desn}_Stempel_1_Formular_punches_segment_{segment}'):
    '''
    Creat a dictionary to save all the loaded rawdata for easily calling out

    Parameters
    -----------------
    data_path: path of the needed datasets

    Returns
    -----------------
    out_data:dict
            dictionary that contains loaded datasets of R1,R2,R3,R4
    '''
    out_data={}
    for exp_desn in expnames:
        row={}
        for segment in segments:
            dbname=os.path.join(data_path, exp_desn, fnpattern.format(segment=segment, exp_desn=exp_desn) )
            #assert os.path.exists(dbname+'.db')
            data=load_all_segments(dbname)
            row[segment] = data
        out_data[exp_desn] =  row
    return out_data```

this how I call the function to load the data:

rawdata_R = 
load_data("\\Users\\Fast\\senseering\\raw_data", ('R1','R2','R3','R4'), ('wait','blanking','preeject','eject'), 'AKF_E_{exp_desn}_Stempel_1_Formular_punches_segment_{segment}')

but I am getting this error and I can not understand what is wrong:

OperationalError                          Traceback (most recent call last)
<ipython-input-17-30cfc39001e5> in <module>
----> 1 rawdata_R = load_data("\\Users\\Fast\\senseering\\raw_data", ('R1','R2','R3','R4'), ('wait','blanking','preeject','eject'), 'AKF_E_{exp_desn}_Stempel_1_Formular_punches_segment_{segment}')

<ipython-input-8-a923a3777194> in load_data(data_path, expnames, segments, fnpattern)
     44             dbname=os.path.join(data_path, exp_desn, fnpattern.format(segment=segment, exp_desn=exp_desn) )
     45             #assert os.path.exists(dbname+'.db')
---> 46             data=load_all_segments(dbname)
     47             row[segment] = data
     48         out_data[exp_desn] =  row

<ipython-input-8-a923a3777194> in load_all_segments(db_name, segment)
      1 def load_all_segments(db_name, segment=""):
----> 2     conn = sqlite3.connect(db_name + ".db")
      3     df_names = pd.read_sql_query("SELECT name FROM sqlite_master WHERE type='table';", conn)
      4     df_all = pd.DataFrame()
      5 

OperationalError: unable to open database file

Can anyone please tell me what's the problem and how to solve it.

Thank you for trying to help.

here is the answer: instead of:

dbname=os.path.join(data_path, exp_desn, fnpattern.format(segment=segment, exp_desn=exp_desn) )

I should have used the following:

dbname=os.path.join(data_path,  fnpattern.format(segment=segment, exp_desn=exp_desn) )

the difference is related to the path of my folder. the first one suggests that in the path folder I am having exp_desn, while I did not have and that is why I could not open it. Once I removed it my data were accessible.

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