Exemplo n.º 1
0
def write(nml, nml_path, force=False, sort=False):
    """Save a namelist to disk using either a file object or its file path.

    File object usage:

    >>> with open(nml_path, 'w') as nml_file:
    >>>     f90nml.write(nml, nml_file)

    File path usage:

    >>> f90nml.write(nml, 'data.nml')

    This function is equivalent to the ``write`` function of the ``Namelist``
    object ``nml``.

    >>> nml.write('data.nml')

    By default, ``write`` will not overwrite an existing file.  To override
    this, use the ``force`` flag.

    >>> nml.write('data.nml', force=True)

    To alphabetically sort the ``Namelist`` keys, use the ``sort`` flag.

    >>> nml.write('data.nml', sort=True)
    """
    # Promote dicts to Namelists
    if not isinstance(nml, Namelist) and isinstance(nml, dict):
        nml_in = Namelist(nml)
    else:
        nml_in = nml

    nml_in.write(nml_path, force=force, sort=sort)
Exemplo n.º 2
0
def write(nml, nml_path, force=False):
    """Output namelist ``nml`` to a Fortran 90 namelist file ``nml_file`` or
    file path ``nml_path``.

    File object usage:

    >>> with open(nml_path, 'w') as nml_file:
    >>>     f90nml.write(nml, nml_file)

    File path usage:

    >>> f90nml.write(nml, 'data.nml')

    This function is equivalent to the ``write`` function of the ``Namelist``
    object ``nml``.

    >>> nml.write('data.nml')

    By default, ``write`` will not overwrite an existing file.  To override
    this, use the ``force`` flag.

    >>> nml.write('data.nml', force=True)"""

    # Promote dicts to Namelists
    if not isinstance(nml, Namelist) and isinstance(nml, dict):
        nml_in = Namelist(nml)
    else:
        nml_in = nml

    nml_in.write(nml_path, force=force)
Exemplo n.º 3
0
def write(nml, nml_path, force=False):
    """Save a namelist to disk using either a file object or its file path.

    File object usage:

    >>> with open(nml_path, 'w') as nml_file:
    >>>     f90nml.write(nml, nml_file)

    File path usage:

    >>> f90nml.write(nml, 'data.nml')

    This function is equivalent to the ``write`` function of the ``Namelist``
    object ``nml``.

    >>> nml.write('data.nml')

    By default, ``write`` will not overwrite an existing file.  To override
    this, use the ``force`` flag.

    >>> nml.write('data.nml', force=True)
    """
    # Promote dicts to Namelists
    if not isinstance(nml, Namelist) and isinstance(nml, dict):
        nml_in = Namelist(nml)
    else:
        nml_in = nml

    nml_in.write(nml_path, force=force)