I'm trying to write a small package that adds a function to the plotly.express
package. I'm trying to get this to work:
>>> import plotly.express as px
>>> import plotly_ecdf
>>> px.ecdf()
'ECDF plot here!'
This actually works as is with this in plotly_ecdf.py
:
# plotly_ecdf.py
import plotly.express as px
def ecdf():
print("ECDF plot here!")
px.ecdf = ecdf
What's weird is that if I haven't already imported plotly.express
, the plotly_ecdf
import also fails:
>>> import plotly_ecdf
>>> px.ecdf()
NameError: name 'px' is not defined
I tried making use of this response. I can access and write variables when called in a function, but I can't it to work during an import statement.
So how do I modify plotly_ecdf.py
to check if plotly.express
is already imported so I can throw an error if it isn't? Bonus points if this can modify whatever alias plotly.express
has been assigned to. Thanks in advance!