def read(self): name = self.name if len(name) < len(MDB_FOLDER) + len('.mdb') or name[-4:] != '.mdb' or name.index(MDB_FOLDER) != 0: raise ValueError("invalid name!") self.name = name[len(MDB_FOLDER):-4] bcolors.printc(bcolors.OKGREEN + bcolors.BOLD, 'read ' + name + '...') #read mdb file try: for row in io.read(name): self._data.append(row) except: pass
def initialize(): """ Not in use. This function is used to create picke objects from datasets. We already provide the pickle files. """ ## To create initial record from meza import io record = io.read(home_folder + 'jee2009.mdb') result = [] for i in range(384977): result.append(next(record)) pickle.dump(result, open(home_folder + "jeeresult.pickle", "wb")) mark = [] for r in result: mark.append(int(r['mark'])) mark.sort(key=lambda i: -int(i)) pickle.dump(mark, open(home_folder + "jeemark.pickle", "wb"))
def mdd(): records = io.read('KD021216.mdb') print(next(records))
from meza import io records = io.read( "C:\1UNRuniversityFolder\Dissertation\Chapter 2-snow-forest\obseravation_analysis\Jemez\valles_dep_0810.mat" ) # only file path, no file objects print(next(records))
# import csv # import pyodbc # mdb = r"D:\_MACIEK_\python_proby\proba\mdb\ZAKRES.mdb" # drv = "{ODBC Driver 17 for SQL Server}" # pwd = "pw" # server = "tcp:myserver.database.windows.net" # con = pyodbc.connect( # r"DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};" # r"DBQ=D:\_MACIEK_\python_proby\proba\mdb\ZAKRES.mdb" # ) # cur = con.cursor() # SQL = "SELECT * FROM ZASIEG" # rows = cur.execute(SQL).fetchall() # cur.close() # con.close() # with open(r"D:\_MACIEK_\python_proby\proba\mdb\aa.csv", "wb") as fou: # csv_writer = csv.writer(fou) # csv_writer.writerows(rows) from meza import io records = io.read(r"D:\_MACIEK_\python_proby\proba\mdb\ZAKRES.mdb") print(next(records))
VERBOSE = True path = os.path.dirname(__file__) # path = path.replace("\\","/") # print("/KD021216.MDB") def mdb_to_pandas(): subprocess.call(["mdb-schema", "KD021216.MDB", "mysql"]) # Get the list of table names with "mdb-tables" table_names = subprocess.Popen(["mdb-tables", "-1", database_path], stdout=subprocess.PIPE).communicate()[0] tables = table_names.splitlines() sys.stdout.flush() # Dump each table as a stringio using "mdb-export", out_tables = {} for rtable in tables: table = rtable.decode() if VERBOSE: print('running table:', table) if table != '': if VERBOSE: print("Dumping " + table) contents = subprocess.Popen( ["mdb-export", database_path, table], stdout=subprocess.PIPE).communicate()[0] temp_io = StringIO(contents.decode()) print(table, temp_io) out_tables[table] = pd.read_csv(temp_io) return out_tables records = io.read('KD021216.MDB') # only file path, no file objects print(next(records))