Skip to content

Commit

Permalink
doc: documented get_sile a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
zerothi committed Jul 6, 2022
1 parent b28d404 commit ea81dcd
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions sisl/io/sile.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ def get_sile(file, *args, **kwargs):
Internally this is roughly equivalent to ``get_sile_class(...)()``.
When the file suffix is not recognized and you know which file-type it is
it is recommended to get the file class from the known suffixes and use that
class to construct the file object, see examples.
Parameters
----------
file : str or pathlib.Path
Expand All @@ -289,6 +293,21 @@ def get_sile(file, *args, **kwargs):
you may query the exact base-class that should be chosen.
If there are several files with similar file-endings this
function returns a random one.
Examples
--------
A file named ``water.dat`` contains the xyz-coordinates as the `xyzSile`.
One can forcefully get the sile by:
>>> obj = get_sile("water.dat{xyzSile}")
Alternatively one can query the xyz file and use that class reference
in future instantiations. This ensures a future proof method without
explicitly typing the Sile object.
>>> cls = get_sile_class("anyfile.xyz")
>>> obj = cls("water.dat")
>>> another_xyz = cls("water2.dat")
"""
cls = kwargs.pop('cls', None)
sile = get_sile_class(file, *args, cls=cls, **kwargs)
Expand Down

0 comments on commit ea81dcd

Please sign in to comment.