recfile

A Python package for efficient reading and writing of files containing fixed length records
Download

recfile Ranking & Summary

Advertisement

  • Rating:
  • License:
  • GPL
  • Publisher Name:
  • Erin Sheldon
  • Publisher web site:
  • http://code.google.com/u/erin.sheldon/

recfile Tags


recfile Description

A Python package for efficient reading and writing of files containing fixed length records recfile is a Python extension module for reading from and writing to files with fixed length records. Data are read into or written from numerical python arrays (numpy). Files can be binary or text files with fixed delimiter, such as csv, tab, or white space.The extension is a C++ class wrapped using SWIG.This extension is especially useful when the structure of the file can be determined at run-time, for example from an ascii header. One implementation of such a format is the SFile module in the esutil python package.Examples: import recfile # Read from a binary file. Number of rows will be determined from # the file data and dtype if not entered, which is slow for text files. file='test.bin' dtype= robj = recfile.Open(file, dtype=dtype) # read all rows and columns data = robj data = robj.read() # read a subset of rows. Can be a slice or sequence/array. data = robj row_list = data = robj data = robj.read(rows=row_list) # get every 3rd in a slice data = robj # read a subset of columns. # In bracket notation, you must specify rows to read the data. data = robj field_list = data = robj # alternative syntax data = robj.read() data = robj.read(columns=column_list) data = robj.read(fields=column_list) # columns/fields are synonyms # Read from a CSV file of the same structure, and only read a subset # of the data. Specifying nrows is not necessary but can speed things up. rows2get= fields2get='field2' robj = recfile.Open('test.csv', delim=",", dtype=dtype, nrows=98321) data = robj] data = robj.read(rows=rows2get, fields=fields2get) # Write a numpy array to a file, with ability to # append. The dtype of the arrays must match upon # successive calls. r = recfile.Open('test.tab', "r+", ",") r.write(my_array) # append more rows r.write(second_array) Requirements: · Python What's New in This Release: · Cleaned up code and documentation, made UPS installation optional. To install the ups directory, use · python setup.py with_ups install --prefix=/some/path


recfile Related Software