1

I have a git repo ,which has a python file and in that file I have defined a function.

for eg :

import pandas as pd

def return_square(num):
    return num*num

This is my function in a file square.py in git repo math_calculation

math_calculation

-- square.py

How to access this function from my local notebook in Jupyter environment

from github import Github
g = Github("***********************")

# Github objects:
for repo in g.get_user().get_repos():
    print(repo.name)

##Use the function square
print(return_square(4))

To get 16 answer in my local notebook

Shubh
  • 585
  • 9
  • 29
  • Is it possible or not possible at all? – Shubh Dec 29 '21 at 13:51
  • 1
    Your code in github is not part of your notebook in any way. So a remote import would not work. You can install it as a pip package, for that you need to package-ize the module. – Kris Dec 29 '21 at 13:57

1 Answers1

1
import requests
request = request.get("https://raw.githbusercontent.com/username/repo/square.py")
with open("square.py", "wb") as f:
  f.write(request.content)

from square import return_square

note: the path should be raw

Nerdy19
  • 134
  • 1
  • 6