nodes: 0, module; 1, function_definition; 2, function_name:write; 3, parameters; 4, block; 5, identifier:nml; 6, identifier:nml_path; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, comment:# Promote dicts to Namelists; 11, if_statement; 12, expression_statement; 13, identifier:force; 14, False; 15, identifier:sort; 16, False; 17, comment:"""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)
      """; 18, boolean_operator; 19, block; 20, else_clause; 21, call; 22, not_operator; 23, call; 24, expression_statement; 25, block; 26, attribute; 27, argument_list; 28, call; 29, identifier:isinstance; 30, argument_list; 31, assignment; 32, expression_statement; 33, identifier:nml_in; 34, identifier:write; 35, identifier:nml_path; 36, keyword_argument; 37, keyword_argument; 38, identifier:isinstance; 39, argument_list; 40, identifier:nml; 41, identifier:dict; 42, identifier:nml_in; 43, call; 44, assignment; 45, identifier:force; 46, identifier:force; 47, identifier:sort; 48, identifier:sort; 49, identifier:nml; 50, identifier:Namelist; 51, identifier:Namelist; 52, argument_list; 53, identifier:nml_in; 54, identifier:nml; 55, identifier:nml
code: 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)