astro py:docs

- Index
- Modules

### Navigation

- next »
- « previous |
- Astropy v0.3 »
- I/O Registry (`astropy.io.registry`) »
- register_identifier

# register_identifier

`astropy.io.registry.``register_identifier`(data_format, data_class, identifier, force=False)

  Associate an identifier function with a specific data type.

  Parameters:

  data_format : str

  > The data type identifier. This is the string that is used to specify the data type when reading/writing.

  data_class : classobj

  > The class of the object that can be written

  identifier : function

  > A function that checks the argument specified to `read` or `write` to determine whether the input can be interpreted as a table of type `data_format`. This function should take the following arguments:

  > > - `origin`: A string `read` or `write` identifying whether the file is to be opened for reading or writing.
  > > - `path`: The path to the file.
  > > - `fileobj`: An open file object to read the file’s contents, or `None` if the file could not be opened.
  > > - `*args`: A list of positional arguments to the `read` or `write` function.
  > > - `**kwargs`: A list of keyword arguments to the `read` or `write` function.

  > One or both of `path` or `fileobj` may be `None`. If they are both `None`, the identifier will need to work from `args[0]`.

  > The function should return True if the input can be identified as being of format `data_format`, and False otherwise.

  force : bool

  > Whether to override any existing function if already present.

  Examples

  To set the identifier based on extensions, for formats that take a filename as a first argument, you can do for example:

      >>> def my_identifier(*args, **kwargs):
      ...     return (isinstance(args[0], basestring) and
      ...             args[0].endswith('.tbl'))
      >>> register_identifier('ipac', Table, my_identifier)