nodes: 0, module; 1, function_definition; 2, function_name:saveAsTextFile; 3, parameters; 4, block; 5, identifier:self; 6, identifier:path; 7, default_parameter; 8, expression_statement; 9, function_definition; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, identifier:compressionCodecClass; 14, None; 15, comment:"""
          Save this RDD as a text file, using string representations of elements.
  
          @param path: path to text file
          @param compressionCodecClass: (None by default) string i.e.
              "org.apache.hadoop.io.compress.GzipCodec"
  
          >>> tempFile = NamedTemporaryFile(delete=True)
          >>> tempFile.close()
          >>> sc.parallelize(range(10)).saveAsTextFile(tempFile.name)
          >>> from fileinput import input
          >>> from glob import glob
          >>> ''.join(sorted(input(glob(tempFile.name + "/part-0000*"))))
          '0\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n'
  
          Empty lines are tolerated when saving to text files.
  
          >>> tempFile2 = NamedTemporaryFile(delete=True)
          >>> tempFile2.close()
          >>> sc.parallelize(['', 'foo', '', 'bar', '']).saveAsTextFile(tempFile2.name)
          >>> ''.join(sorted(input(glob(tempFile2.name + "/part-0000*"))))
          '\\n\\n\\nbar\\nfoo\\n'
  
          Using compressionCodecClass
  
          >>> tempFile3 = NamedTemporaryFile(delete=True)
          >>> tempFile3.close()
          >>> codec = "org.apache.hadoop.io.compress.GzipCodec"
          >>> sc.parallelize(['foo', 'bar']).saveAsTextFile(tempFile3.name, codec)
          >>> from fileinput import input, hook_compressed
          >>> result = sorted(input(glob(tempFile3.name + "/part*.gz"), openhook=hook_compressed))
          >>> b''.join(result).decode('utf-8')
          u'bar\\nfoo\\n'
          """; 16, function_name:func; 17, parameters; 18, block; 19, assignment; 20, assignment; 21, identifier:compressionCodecClass; 22, block; 23, else_clause; 24, identifier:split; 25, identifier:iterator; 26, for_statement; 27, identifier:keyed; 28, call; 29, attribute; 30, True; 31, expression_statement; 32, expression_statement; 33, block; 34, identifier:x; 35, identifier:iterator; 36, block; 37, attribute; 38, argument_list; 39, identifier:keyed; 40, identifier:_bypass_serializer; 41, assignment; 42, call; 43, expression_statement; 44, if_statement; 45, if_statement; 46, expression_statement; 47, identifier:self; 48, identifier:mapPartitionsWithIndex; 49, identifier:func; 50, identifier:compressionCodec; 51, call; 52, attribute; 53, argument_list; 54, call; 55, not_operator; 56, block; 57, call; 58, block; 59, yield; 60, attribute; 61, argument_list; 62, call; 63, identifier:saveAsTextFile; 64, identifier:path; 65, identifier:compressionCodec; 66, attribute; 67, argument_list; 68, call; 69, expression_statement; 70, identifier:isinstance; 71, argument_list; 72, expression_statement; 73, identifier:x; 74, attribute; 75, identifier:forName; 76, identifier:compressionCodecClass; 77, attribute; 78, argument_list; 79, call; 80, identifier:saveAsTextFile; 81, identifier:path; 82, identifier:isinstance; 83, argument_list; 84, assignment; 85, identifier:x; 86, identifier:unicode; 87, assignment; 88, attribute; 89, identifier:Class; 90, attribute; 91, identifier:map; 92, call; 93, attribute; 94, argument_list; 95, identifier:x; 96, tuple; 97, identifier:x; 98, call; 99, identifier:x; 100, call; 101, attribute; 102, identifier:lang; 103, identifier:keyed; 104, identifier:_jrdd; 105, attribute; 106, argument_list; 107, attribute; 108, identifier:map; 109, call; 110, identifier:unicode; 111, identifier:bytes; 112, identifier:unicode; 113, argument_list; 114, attribute; 115, argument_list; 116, attribute; 117, identifier:java; 118, attribute; 119, identifier:BytesToString; 120, identifier:keyed; 121, identifier:_jrdd; 122, attribute; 123, argument_list; 124, identifier:x; 125, identifier:x; 126, identifier:encode; 127, string:"utf-8"; 128, attribute; 129, identifier:_jvm; 130, attribute; 131, identifier:_jvm; 132, attribute; 133, identifier:BytesToString; 134, identifier:self; 135, identifier:ctx; 136, identifier:self; 137, identifier:ctx; 138, attribute; 139, identifier:_jvm; 140, identifier:self; 141, identifier:ctx
code: def saveAsTextFile(self, path, compressionCodecClass=None):
          """
          Save this RDD as a text file, using string representations of elements.
  
          @param path: path to text file
          @param compressionCodecClass: (None by default) string i.e.
              "org.apache.hadoop.io.compress.GzipCodec"
  
          >>> tempFile = NamedTemporaryFile(delete=True)
          >>> tempFile.close()
          >>> sc.parallelize(range(10)).saveAsTextFile(tempFile.name)
          >>> from fileinput import input
          >>> from glob import glob
          >>> ''.join(sorted(input(glob(tempFile.name + "/part-0000*"))))
          '0\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n'
  
          Empty lines are tolerated when saving to text files.
  
          >>> tempFile2 = NamedTemporaryFile(delete=True)
          >>> tempFile2.close()
          >>> sc.parallelize(['', 'foo', '', 'bar', '']).saveAsTextFile(tempFile2.name)
          >>> ''.join(sorted(input(glob(tempFile2.name + "/part-0000*"))))
          '\\n\\n\\nbar\\nfoo\\n'
  
          Using compressionCodecClass
  
          >>> tempFile3 = NamedTemporaryFile(delete=True)
          >>> tempFile3.close()
          >>> codec = "org.apache.hadoop.io.compress.GzipCodec"
          >>> sc.parallelize(['foo', 'bar']).saveAsTextFile(tempFile3.name, codec)
          >>> from fileinput import input, hook_compressed
          >>> result = sorted(input(glob(tempFile3.name + "/part*.gz"), openhook=hook_compressed))
          >>> b''.join(result).decode('utf-8')
          u'bar\\nfoo\\n'
          """
          def func(split, iterator):
              for x in iterator:
                  if not isinstance(x, (unicode, bytes)):
                      x = unicode(x)
                  if isinstance(x, unicode):
                      x = x.encode("utf-8")
                  yield x
          keyed = self.mapPartitionsWithIndex(func)
          keyed._bypass_serializer = True
          if compressionCodecClass:
              compressionCodec = self.ctx._jvm.java.lang.Class.forName(compressionCodecClass)
              keyed._jrdd.map(self.ctx._jvm.BytesToString()).saveAsTextFile(path, compressionCodec)
          else:
              keyed._jrdd.map(self.ctx._jvm.BytesToString()).saveAsTextFile(path)