Warning
This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.
open_file¶
-
open_file
(path_arg, mode='r')[source]¶ Decorator to ensure clean opening and closing of files.
Parameters: Returns: _open_file – Function which cleanly executes the io.
Return type: Examples
Decorate functions like this:
@open_file(0,'r') def read_function(pathname): pass @open_file(1,'w') def write_function(G,pathname): pass @open_file(1,'w') def write_function(G, pathname='graph.dot') pass @open_file('path', 'w+') def another_function(arg, **kwargs): path = kwargs['path'] pass