class_docstr: Magics to interact with the underlying OS (shell-type functionality).
      
class_docstr_tok: ["Magics","to","interact","with","the","underlying","OS","(","shell-type","functionality",")","."]
docstr: Write the contents of the cell to a file.
  
  The file will be overwritten unless the -a (--append) flag is specified.
docstr_tok: ["Write","the","contents","of","the","cell","to","a","file",".","The","file","will","be","overwritten","unless","the","-a","(","--","append",")","flag","is","specified","."]
code: def writefile(self, line, cell):
      """Write the contents of the cell to a file.
  
      The file will be overwritten unless the -a (--append) flag is specified.
      """
      args = magic_arguments.parse_argstring(self.writefile, line)
      if re.match(r'^(\'.*\')|(".*")$', args.filename):
          filename = os.path.expanduser(args.filename[1:-1])
      else:
          filename = os.path.expanduser(args.filename)
  
      if os.path.exists(filename):
          if args.append:
              print("Appending to %s" % filename)
          else:
              print("Overwriting %s" % filename)
      else:
          print("Writing %s" % filename)
  
      mode = "a" if args.append else "w"
      with io.open(filename, mode, encoding="utf-8") as f:
          f.write(cell)
  
imports: import io
  import os
  import pathlib
  import re
  import sys
  from pprint import pformat
  from IPython.core import magic_arguments
  from IPython.core import oinspect
  from IPython.core import page
  from IPython.core.alias import AliasError, Alias
  from IPython.core.error import UsageError
  from IPython.core.magic import Magics, compress_dhist, magics_class, line_magic, cell_magic, line_cell_magic
  from IPython.testing.skipdoctest import skip_doctest
  from IPython.utils.openpy import source_to_unicode
  from IPython.utils.process import abbrev_cwd
  from IPython.utils.terminal import set_term_title
  from traitlets import Bool
  from warnings import warn
label_desc: Use image node_id 20 for calling the OSMagics obj's underlying member method code with example usage: obj.writefile(line, cell) without return types