parameters: (self, graph, fname, nodeAttributes = {}, edgeAttributes = {})
docstring: Writes a NetworKit graph to the specified file fname. 
  		
  		Parameters:
  		-----------
  		graph: a NetworKit::Graph python object 
  		fname: the desired file path and name to be written to
  		nodeAttributes: optional dictionary of node attributes in the form attribute name => list of attribute values
  		edgeAttributes: optional dictionary of edge attributes in the form attribute name => list of attribute values
docstring_summary: Writes a NetworKit graph to the specified file fname. 
  		
  		Parameters:
  		-----------
  		graph: a NetworKit::Graph python object 
  		fname: the desired file path and name to be written to
  		nodeAttributes: optional dictionary of node attributes in the form attribute name => list of attribute values
  		edgeAttributes: optional dictionary of edge attributes in the form attribute name => list of attribute values
docstring_tokens: Writes a NetworKit graph to the specified file fname . Parameters : ----------- graph : a NetworKit :: Graph python object fname : the desired file path and name to be written to nodeAttributes : optional dictionary of node attributes in the form attribute name = > list of attribute values edgeAttributes : optional dictionary of edge attributes in the form attribute name = > list of attribute values
function: def write(self, graph, fname, nodeAttributes = {}, edgeAttributes = {}):
  		""" Writes a NetworKit graph to the specified file fname. 
  		
  		Parameters:
  		-----------
  		graph: a NetworKit::Graph python object 
  		fname: the desired file path and name to be written to
  		nodeAttributes: optional dictionary of node attributes in the form attribute name => list of attribute values
  		edgeAttributes: optional dictionary of edge attributes in the form attribute name => list of attribute values
  		"""
  		# reset some internal variables in case more graphs are written with the same instance
  		self.edgeIdCounter = 0
  		self.dir_str = ''
  
  		if len(edgeAttributes) > 0 and not graph.hasEdgeIds():
  			raise RuntimeError("Error, graph must have edge ids if edge attributes are given")
  
  		# start with the root element and the right header information
  		root = ET.Element('graphml')
  		root.set("xmlnsi","http://graphml.graphdrawing.org/xmlns")
  		root.set("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")
  		root.set("xsi:schemaLocation","http://graphml.graphdrawing.org/xmlns \
  			http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd")
  
  		maxAttrKey = 1
  		# if the graph is weighted, add the attribute
  		if graph.isWeighted():
  			attrElement = ET.SubElement(root,'key')
  			attrElement.set('for','edge')
  			attrElement.set('id', 'd1')
  			attrElement.set('attr.name','weight')
  			attrElement.set('attr.type','double')
  			maxAttrKey += 1
  
  		attrKeys = {}
  		import numbers
  		import itertools
  		for attType, attName, attData in itertools.chain(
  			map(lambda d : ('node', d[0], d[1]), nodeAttributes.items()),
  			map(lambda d : ('edge', d[0], d[1]), edgeAttributes.items())):
  
  			attrElement = ET.SubElement(root, 'key')
  			attrElement.set('for', attType)
  			attrElement.set('id', 'd{0}'.format(maxAttrKey))
  			attrKeys[(attType, attName)] = 'd{0}'.format(maxAttrKey)
  			maxAttrKey += 1
  			attrElement.set('attr.name', attName)
  			if len(attData) == 0:
  				attrElement.set('attr.type', 'int')
  			elif isinstance(attData[0], bool):
  				attrElement.set('attr.type', 'boolean')
  				# special handling for boolean attributes: convert boolean into lowercase string
  				if attType == 'edge':
  					edgeAttributes[attName] = [ str(d).lower() for d in attData ]
  				else:
  					nodeAttributes[attName] = [ str(d).lower() for d in attData ]
  			elif isinstance(attData[0], numbers.Integral):
  				attrElement.set('attr.type', 'int')
  			elif isinstance(attData[0], numbers.Real):
  				attrElement.set('attr.type', 'double')
  			else:
  				attrElement.set('attr.type', 'string')
  
  
  		# create graph element with appropriate information
  		graphElement = ET.SubElement(root,"graph")
  		if graph.isDirected():
  			graphElement.set('edgedefault', 'directed')
  			self.dir_str = 'true'
  		else:
  			graphElement.set('edgedefault', 'undirected')
  			self.dir_str = 'false'
  
  		# Add nodes
  		for n in graph.iterNodes():
  			nodeElement = ET.SubElement(graphElement,'node')
  			nodeElement.set('id', str(n))
  			for attName, attData in nodeAttributes.items():
  				dataElement = ET.SubElement(nodeElement, 'data')
  				dataElement.set('key', attrKeys[('node', attName)])
  				dataElement.text = str(attData[n])
  
  		# in the future: more attributes
  	        #for a in n.attributes():
          	#    if a != 'label':
  	        #        data = doc.createElement('data')
          	#        data.setAttribute('key', a)
  	        #        data.appendChild(doc.createTextNode(str(n[a])))
          	#        node.appendChild(data)
  
  		# Add edges
  		def addEdge(u, v, w, eid):
  			edgeElement = ET.SubElement(graphElement,'edge')
  			edgeElement.set('directed', self.dir_str)
  			edgeElement.set('target', str(v))
  			edgeElement.set('source', str(u))
  			if graph.hasEdgeIds():
  				edgeElement.set('id', "e{0}".format(eid))
  			else:
  				edgeElement.set('id', "e{0}".format(self.edgeIdCounter))
  				self.edgeIdCounter += 1
  			if graph.isWeighted():
  				# add edge weight
  				dataElement = ET.SubElement(edgeElement,'data')
  				dataElement.set('key','d1')
  				dataElement.text = str(w)
  			for attName, attData in edgeAttributes.items():
  				dataElement = ET.SubElement(edgeElement, 'data')
  				dataElement.set('key', attrKeys[('edge', attName)])
  				dataElement.text = str(attData[eid])
  		graph.forEdges(addEdge)
  
  	#TODO: optional prettify function for formatted output of xml files
  		tree = ET.ElementTree(root)
  		tree.write(fname,"utf-8",True)
function_tokens: def write ( self , graph , fname , nodeAttributes = { } , edgeAttributes = { } ) : # reset some internal variables in case more graphs are written with the same instance self . edgeIdCounter = 0 self . dir_str = '' if len ( edgeAttributes ) > 0 and not graph . hasEdgeIds ( ) : raise RuntimeError ( "Error, graph must have edge ids if edge attributes are given" ) # start with the root element and the right header information root = ET . Element ( 'graphml' ) root . set ( "xmlnsi" , "http://graphml.graphdrawing.org/xmlns" ) root . set ( "xmlns:xsi" , "http://www.w3.org/2001/XMLSchema-instance" ) root . set ( "xsi:schemaLocation" , "http://graphml.graphdrawing.org/xmlns \
  			http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd" ) maxAttrKey = 1 # if the graph is weighted, add the attribute if graph . isWeighted ( ) : attrElement = ET . SubElement ( root , 'key' ) attrElement . set ( 'for' , 'edge' ) attrElement . set ( 'id' , 'd1' ) attrElement . set ( 'attr.name' , 'weight' ) attrElement . set ( 'attr.type' , 'double' ) maxAttrKey += 1 attrKeys = { } import numbers import itertools for attType , attName , attData in itertools . chain ( map ( lambda d : ( 'node' , d [ 0 ] , d [ 1 ] ) , nodeAttributes . items ( ) ) , map ( lambda d : ( 'edge' , d [ 0 ] , d [ 1 ] ) , edgeAttributes . items ( ) ) ) : attrElement = ET . SubElement ( root , 'key' ) attrElement . set ( 'for' , attType ) attrElement . set ( 'id' , 'd{0}' . format ( maxAttrKey ) ) attrKeys [ ( attType , attName ) ] = 'd{0}' . format ( maxAttrKey ) maxAttrKey += 1 attrElement . set ( 'attr.name' , attName ) if len ( attData ) == 0 : attrElement . set ( 'attr.type' , 'int' ) elif isinstance ( attData [ 0 ] , bool ) : attrElement . set ( 'attr.type' , 'boolean' ) # special handling for boolean attributes: convert boolean into lowercase string if attType == 'edge' : edgeAttributes [ attName ] = [ str ( d ) . lower ( ) for d in attData ] else : nodeAttributes [ attName ] = [ str ( d ) . lower ( ) for d in attData ] elif isinstance ( attData [ 0 ] , numbers . Integral ) : attrElement . set ( 'attr.type' , 'int' ) elif isinstance ( attData [ 0 ] , numbers . Real ) : attrElement . set ( 'attr.type' , 'double' ) else : attrElement . set ( 'attr.type' , 'string' ) # create graph element with appropriate information graphElement = ET . SubElement ( root , "graph" ) if graph . isDirected ( ) : graphElement . set ( 'edgedefault' , 'directed' ) self . dir_str = 'true' else : graphElement . set ( 'edgedefault' , 'undirected' ) self . dir_str = 'false' # Add nodes for n in graph . iterNodes ( ) : nodeElement = ET . SubElement ( graphElement , 'node' ) nodeElement . set ( 'id' , str ( n ) ) for attName , attData in nodeAttributes . items ( ) : dataElement = ET . SubElement ( nodeElement , 'data' ) dataElement . set ( 'key' , attrKeys [ ( 'node' , attName ) ] ) dataElement . text = str ( attData [ n ] ) # in the future: more attributes #for a in n.attributes(): #    if a != 'label': #        data = doc.createElement('data') #        data.setAttribute('key', a) #        data.appendChild(doc.createTextNode(str(n[a]))) #        node.appendChild(data) # Add edges def addEdge ( u , v , w , eid ) : edgeElement = ET . SubElement ( graphElement , 'edge' ) edgeElement . set ( 'directed' , self . dir_str ) edgeElement . set ( 'target' , str ( v ) ) edgeElement . set ( 'source' , str ( u ) ) if graph . hasEdgeIds ( ) : edgeElement . set ( 'id' , "e{0}" . format ( eid ) ) else : edgeElement . set ( 'id' , "e{0}" . format ( self . edgeIdCounter ) ) self . edgeIdCounter += 1 if graph . isWeighted ( ) : # add edge weight dataElement = ET . SubElement ( edgeElement , 'data' ) dataElement . set ( 'key' , 'd1' ) dataElement . text = str ( w ) for attName , attData in edgeAttributes . items ( ) : dataElement = ET . SubElement ( edgeElement , 'data' ) dataElement . set ( 'key' , attrKeys [ ( 'edge' , attName ) ] ) dataElement . text = str ( attData [ eid ] ) graph . forEdges ( addEdge ) #TODO: optional prettify function for formatted output of xml files tree = ET . ElementTree ( root ) tree . write ( fname , "utf-8" , True )