A
A
Amati2020-12-08 09:48:08
Python
Amati, 2020-12-08 09:48:08

How to import a class from a file that is on another site?

The main part of the main.py script:

my_bot = InBot('./data.txt')
my_bot.login()
green = True
while green:
    my_bot.metod_1()
    my_bot.metod_2()
    my_bot.metod_3()
    if not green:
        break


my_bot is an instance of the InBot class. All in one file.
Is it possible to transfer the InBot class to another file on another site, and how can I import it into main.py from there?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Amati, 2020-12-08
@Amati

I don't understand why this site is different.

I want to copy the script to an exe file. And distribute to people. There will be bugs. And it's easier to fix a bug in the class than to edit the script for each person individually.
But that's what I think.. I could be wrong..

O
o5a, 2020-12-08
@o5a

It’s not clear what the other site has to do with it, but if the question is how to select a class, then so be it.
Save the entire InBot class in a file like inbot.py in the same folder as main.py
then just import into main.py

from inbot import InBot

my_bot = InBot('./data.txt')

If we are talking about importing from a file from another site, then nothing. And it is not clear how such a task arose.

Q
QWERTYUIOPas, 2020-12-08
@QWERTYUIOPas

Like this:

try:import requests
except Exception:from os import system;system('pip install reqests')
import requests
code=requests.get(URL).text
exec(code)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question