I am very confused because I have a python server up and running on https://python-server-password-manager.wotsitgamer.repl.co/. On that server there is a file named "main.py". I need to link a function from that file to the local python application. I tried to use the following:
import https://python-server-password-manager.wotsitgamer.repl.co/
... but that just gives me an error.
Any help would be great.
You cannot directly import a file remotely, but you can download it then execute it by importing it.
from requests import get
# Download the file
code = get("https://python-server-password-manager.wotsitgamer.repl.co/main.py").text
# Write the data to a file
with open("main.py", "w") as f:
f.write(code)
# Run the code
import main
Update:
As mentioned in the comments, OP wants to interact with the remote script as if it is located locally (specifically, transferal of data). In that case, there is not really a better option than running an API on the website, or a shared database of some sort (e.g., Firebase).
You can play around with Pythons ModuleFinder.
I have never done it, but this project is an example for that.
It is in my opinion a bit of an over kill, and a more trivial solution will be to fetch the files to your local machine, and import in the usual way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With