mcsas.datafile.datafile module

class DataFile(filename, **kwargs)[source]

Bases: object

Base class for handling data files. Can be initialized with a file (name) to read or with a data array.

Test error behaviour >>> from utils import DataFile, getTempFileName, getTempFile, FileNotFound >>> fn = getTempFileName() >>> try: DataFile.checkFilename(fn) ... except FileNotFound, e: str(e).find(fn) > 0 True

Prepare test data file >>> fd = getTempFile() >>> l = [‘123 234n’, ‘1,23 43.4rn’, ‘2.3; 34,4n’, ... ‘21.2 42 2n’, ‘23,2 3.4 n’] >>> fd.writelines(l) >>> fd.close()

Test data parsing >>> df = DataFile() >>> df.loadFile(fd.name) [(‘123’, ‘234’), (‘1.23’, ‘43.4’), (‘2.3’, ‘34.4’), (‘21.2’, ‘42’, ‘2’), (‘23.2’, ‘3.4’)]

Remove test data finally >>> import os >>> if os.path.isfile(fd.name): ... os.remove(fd.name)

classmethod extensions()[source]

Warning

method ‘datafile.datafile.DataFile.extensions’ undocumented

fileFilter

classmethod(function) -> method

Convert a function to be a class method.

A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom:

class C:
def f(cls, arg1, arg2, ...): ... f = classmethod(f)

It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class. If a class method is called for a derived class, the derived class object is passed as the implied first argument.

Class methods are different than C++ or Java static methods. If you want those, see the staticmethod builtin.

filename

Absolute path name of this file.

getDataObj()[source]

Creates and returns the appropriate DataObj instance for this file type.

name

The plain name of the file with path and extension stripped.

readFile(**kwargs)[source]

Gets a proper file name and returns file data. May modify the instance. To be reimplemented.

static sanitizeReadFilename(filename)[source]

Checks provided filename for plausibility and updates LastPath.

classmethod sanitizeWriteFilename(filename)[source]

Checks and sets the file name to write to.

setFilename(filename)[source]

Checks provided filename for plausibility and updates LastPath

write(filename, **kwargs)[source]

Warning

method ‘datafile.datafile.DataFile.write’ undocumented

classmethod writeData(filename, data, **kwargs)[source]

Convenience method to write data directly to file.

classmethod writeFile(filename, data, **kwargs)[source]

Gets a proper file name and numpy array and writes it to file. Reimplement this.

classproperty(func)

Warning

function ‘datafile.datafile.classproperty’ undocumented