Decorator to ensure clean opening and closing of files.
Parameters : | path_arg : int
mode : str
|
---|---|
Returns : | _open_file : function
|
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(path, 'w+')
def another_function(arg, **kwargs):
path = kwargs['path']
pass