Skip to main content

Save and load vars, functions ...

Project description

Save and load vars, functions, objects ...

How to save the global vars (or any other variable)

# Create a file



import pandas as pd

from save_load_vars import save_vars_pkl



df = pd.read_csv(

    "https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv"

)





def myfunction(x):

    return str(x) + "bbbb"





myfunction2 = lambda k: myfunction(k)

partofframe = df.Name.copy()[:50]



# Save the global vars 

save_vars_pkl(g=globals(), folder=f"f:\\pklsavetest", interface="dill", protocol=None)

How to load the saved data

from save_load_vars import load_vars_pkl





load_vars_pkl(folder=f'f:\\pklsavetest',

              name=__name__,interface='dill')



print(df)

print(myfunction(44))

print(partofframe)

print(df.Cabin.apply(myfunction2))

How to create global variables from a dict

from save_load_vars import globals_from_dict

didi={

    'a':'bobo',

    'b':'bobao',

    'c': [4,3,3]

}

globals_from_dict(didi,__name__)

print(a)

print(b)

print(c)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

save_load_vars-0.11.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

save_load_vars-0.11-py3-none-any.whl (5.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page