API References
pypickle is to save and load variables from pickle files.
Name : pypickle.py Author : E.Taskesen Contact : erdogant@gmail.com Github : https://github.com/erdogant/pypickle Licence : See licences
- pypickle.pypickle.check_logger(verbose: [<class 'str'>, <class 'int'>] = 'info')
Check the logger.
- pypickle.pypickle.clean(filename: str) str
Clean the filename to make sure the file can be saved on disk.
Description
The following characters are replaced from the filename: ‘&’, ‘,’, ‘?’, ‘$’, ‘!’ ‘/’, ‘’ with character: ‘_’
- param filename:
Filename.
- type filename:
str
- returns:
TYPE – filename
- rtype:
str
Example
>>> import pypickle >>> filename = 't/st.pkl' >>> data = [1,2,3,4,5] >>> filename = pypickle.clean(filename) >>> # Save >>> status = pypickle.save(filename, data) >>> # Load file >>> data = pypickle.load(filepath)
- pypickle.pypickle.convert_verbose_to_new(verbose)
Convert old verbosity to the new.
- pypickle.pypickle.get_logger()
Return logger status.
- pypickle.pypickle.load(filepath: str, fix_imports: bool = True, encoding: str = 'ASCII', errors: str = 'strict', verbose: int = 3)
Load pickle files for input variables.
- Parameters:
filepath (str) – Pathname to store pickle files.
fix_imports (bool, (default=True)) – fix_imports are used for compatibility support for pickle stream generated by Python 2. If fix_imports is true, pickle will try to map the old Python 2 names to the new names used in Python 3.
encoding (str, (default: "ASCII")) – encoding tell pickle how to decode 8-bit string instances pickled by Python 2. The encoding can be “bytes” to read these 8-bit string instances as bytes objects. Using encoding=”latin1” is required for unpickling NumPy arrays and instances of datetime, date and time pickled by Python 2.
errors (str, (default: "strict")) – errors tell pickle how to decode 8-bit string instances pickled by Python 2.
verbose (int, optional) – Show message. A higher number gives more informatie. The default is 3.
- Returns:
Status of succes
- Return type:
bool [True,False].
Example
>>> import pypickle >>> filepath = 'test.pkl' >>> data = [1,2,3,4,5] >>> status = pypickle.save(filepath, data) >>> # Load file >>> data = pypickle.load(filepath)
- pypickle.pypickle.save(filepath: str, var, overwrite: bool = False, fix_imports: bool = True, verbose: int = 20)
Save pickle file for input variables.
- Parameters:
filepath (str) – Pathname to store pickle files.
var ({list, object, dataframe, etc}) – Name of list or dict or anything else that needs to be stored.
fix_imports (bool, (default=True)) – fix_imports are used for compatibility support for pickle stream generated by Python 2. If fix_imports is true, pickle will try to map the old Python 2 names to the new names used in Python 3.
overwrite (bool, (default=False)) – Overwite file if exists.
verbose (int, (default: 20)) – Print progress to screen. The default is 20. 10:Debug, 20:Info, 30:Warn 40:Error, 60 or 0:Silent
- Returns:
Status of succes
- Return type:
bool [True,False].
Example
>>> import pypickle >>> filepath = './temp/test.pkl' >>> data = [1,2,3,4,5] >>> status = pypickle.save(filepath, data)
- pypickle.pypickle.set_logger(verbose: [<class 'str'>, <class 'int'>] = 'info')
Set the logger for verbosity messages.
- Parameters:
verbose ([str, int], default is 'info' or 20) – Set the verbose messages using string or integer values. * [0, 60, None, ‘silent’, ‘off’, ‘no’]: No message. * [10, ‘debug’]: Messages from debug level and higher. * [20, ‘info’]: Messages from info level and higher. * [30, ‘warning’]: Messages from warning level and higher. * [50, ‘critical’]: Messages from critical level and higher.
- Returns:
None.
> # Set the logger to warning
> set_logger(verbose=’warning’)
> # Test with different messages
> logger.debug(“Hello debug”)
> logger.info(“Hello info”)
> logger.warning(“Hello warning”)
> logger.critical(“Hello critical”)