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
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for save_load_vars-0.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ce80d5fd3ef27d0161c7d5abc74317da80d9efdede690ad04a5a3f3878a2115 |
|
MD5 | a8c70ddff6fd97d018d1a20e21290029 |
|
BLAKE2b-256 | e33dc1bfc110128cc45cc4118a969de631ab7d3006347672f16964bfb8c6c75a |