Some utility functions using the Python Standard Library.
Project description
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, # The object whose source code you want to retrieve.
markdown=False): # Returns the source code formatted as markdown
"""
Returns the source code of an object, with an optional markdown formatting.
"""
# Get the source code of the object
source = inspect.getsource(obj)
if markdown:
# Format the source code as markdown code block
source = f"```python\n{source}\n```"
# Check if the code is running in Jupyter Notebook
try:
get_ipython
from IPython.display import Markdown
# Format the source code as an IPython Markdown object
source = Markdown(source)
except NameError:
# If not in Jupyter Notebook, do nothing
pass
# Return the formatted source code
return source
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
cjm-psl-utils-0.0.1.tar.gz
(4.8 kB
view hashes)
Built Distribution
Close
Hashes for cjm_psl_utils-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2774f08b04393a758fd409a0b0dd6f23698df494035f9f30f759d3816886f6a8 |
|
MD5 | dda06082c59875fc3b89be6902fac612 |
|
BLAKE2b-256 | 08316ce0611be040dcf2e9665f12d57244284b6ebe863416112b9ccd699c3d48 |