def save_variables_to_shelve(file_path, variables):
mashelf = shelve.open(file_path, '<STR_LIT:n>')<EOL>for vn in variables.keys():<EOL><INDENT>try:<EOL><INDENT>mashelf[vn] = variables[vn]<EOL><DEDENT>except KeyError as ke:<EOL><INDENT>raise Exception('<STR_LIT>'.format(vn)) from ke<EOL><DEDENT><DEDENT>mashelf.close()<EOL>
Parameters
----------
file_path: str

variables: dict
    Dictionary with objects. Object name -> object

Notes
-----
    Before calling this function, create a varlist this way:

    shelfvars = []
    for v in varnames:
        shelfvars.append(eval(v))

    #to_restore variables from shelf
    my_shelf = shelve.open(filename)
    for key in my_shelf:
       globals()[key]=my_shelf[key]
    my_shelf.close()