cjm-psl-utils
This file will become your README and also the index of your
documentation.
Install
pip install cjm_psl_utils
How to use
get_source_code
from cjm_psl_utils.core import get_source_code
get_source_code(get_source_code, markdown=True)
def get_source_code(obj:object,
markdown=False,
remove_documentation=False):
"""
Returns the source code of an object, with an optional markdown formatting.
"""
source = inspect.getsource(obj)
if remove_documentation:
in_docstring = False
lines = source.split('\n')
source = ''
for line in lines:
if line.strip().startswith(('\'\'\'', '\"\"\"')):
in_docstring = not in_docstring
elif not in_docstring:
source += line + '\n'
source = '\n'.join([line for line in source.split('\n')
if not line.strip().startswith(('#'))])
source = source.replace('\n\n', '\n')
if markdown:
source = f"```python\n{source}\n```"
try:
get_ipython
from IPython.display import Markdown
source = Markdown(source)
except NameError:
pass
return source
from cjm_psl_utils.core import file_extract
from pathlib import Path
fname = "../images/images.zip"
dest = Path("./images")
print(dest.exists())
file_extract(fname, dest)
print(dest.exists())
print(list(os.walk(dest))[0][2])
False
True
['cat.jpg']