operatorequals/httpimport

How to import a gist

kolibril13 opened this issue · 3 comments

Coming from this StackOverflow question, how can I import a hello() function from this gist:
https://gist.github.com/kolibril13/fc84c6940a8aeab8071c5d54d4df3a7b ?
My idea would be something like:

import httpimport
with httpimport.load("https://gist.githubusercontent.com/kolibril13/fc84c6940a8aeab8071c5d54d4df3a7b/raw/bedba99860d301fdc20edac5291b52359a46d1e3/"):
    import hello

I am grateful for any help 👍🏼

Hello!
That's almost right.

>>> import httpimport
>>> with httpimport.remote_repo(['hello'],"https://gist.githubusercontent.com/kolibril13/fc84c6940a8aeab8071c5d54d4df3a7b/raw/bedba99860d301fdc20edac5291b52359a46d1e3/"):
...     import hello
... 
>>> hello
<module 'hello' from 'https://gist.githubusercontent.com/kolibril13/fc84c6940a8aeab8071c5d54d4df3a7b/raw/53227fbc75d0c1bfdda41a786ae99fa04f24b429//hello.py'>
>>> hello.hello()
Hello world

The initial ['hello'] list is for the finder to expect these packages/modules in the URL.

Ohh, this is amazing, thanks a lot!
It's working as expected on my machine.
If you want, I can even make a pull request and add this example to the readme.
And if so, would you make a hello_world gist from your account to which I can refer to as an URL?
I think that would make sense as you are as well the owner of this repo ;)

I'm glad it works!

Please make the PR whenever you have time!
You can use this gist I made for this purpose:
https://gist.github.com/operatorequals/ee5049677e7bbc97af2941d1d3f04ace