Ask coding questions

← Back to all posts
Python Chat
AtharvGoel (3)

How can I create two python repls, so that when I run them, what I type in one repl will show up on the other?

Answered by PattanAhmed (1411) [earned 5 cycles]
View Answer
Comments
hotnewtop
PattanAhmed (1411)

@AtharvGoel Hi,
You can use an XPath to locate the <iframe>:

iframe = driver.find_element_by_xpath("//iframe[@name='Dialogue Window']")

Then switch_to the <iframe>:

driver.switch_to.frame(iframe)

Here's how to switch back to the default content (out of the <iframe>):

driver.switch_to.default_content()

Reference:- Click here

Try

and tell me the results

Thanks!
Hope this helps

Coder100 (18873)

that's selenium...
that's not what he's looking for @PattanAhmed

AtharvGoel (3)

@PattanAhmed I'll have to look into it. Never heard of it. I'm a little busy right now, but I'll look later.

AtharvGoel (3)

@PattanAhmed I looked into it a little bit, but I don't think iframe is what I'm looking for. I'm just trying to basically send data from one repl.run to another. I don't want to create a display or something like that

PattanAhmed (1411)

@AtharvGoel Oh no!
The only way is to Copy-Paste the code, I think.
Thanks!

AtharvGoel (3)

@PattanAhmed Also, when I created a basic selenium program, it worked on the repl, but not the repl.run. It said connection closed abruptly.

AtharvGoel (3)

@PattanAhmed Copy-Paste the code??? I'm trying to send info from one repl.run to another.

PattanAhmed (1411)

@AtharvGoel Yes...
Copy the code from one Repl and paste it on another...
I think that's the only method!

AtharvGoel (3)

@PattanAhmed That's not what I'm trying to do. If I type hi in one repl.run, I want it to send that info to another repl.run where it will print whatever it recieved - in this case hi

PattanAhmed (1411)

@AtharvGoel Simple code using dirsync:

from dirsync import sync
source_path = '/Give/Source/File/Here'
target_path = '/Give/Target/File/Here'

sync(source_path, target_path, 'sync') #for syncing one way
sync(target_path, source_path, 'sync') #for syncing the opposite way

Reference:- Click here

Hope this helps

AtharvGoel (3)

@PattanAhmed Still not what I want. It's similar, but I have two different repls. I don't want to change one file and it will change the other. I'm trying to send data.

PattanAhmed (1411)

@AtharvGoel Oh.
So you want to transfer one file data to another file.
Not sync.
Right?

AtharvGoel (3)

@PattanAhmed Kind of, I don't want it to change the code or edit a file or something. Just set the value of a variable to a variable from a different repl.

PattanAhmed (1411)

@AtharvGoel Oh!
Check this code:-

import socket
import sys
s = socket.socket()
s.bind(("localhost",9999))
s.listen(10) # Accepts up to 10 connections.

while True:
    sc, address = s.accept()

    print address
    i=1
    f = open('file_'+ str(i)+".pdf",'wb') #open in binary
    i=i+1
    while (True):       
    # receive data and write it to file
        l = sc.recv(1024)
        while (l):
                f.write(l)
                l = sc.recv(1024)
    f.close()


    sc.close()

s.close()

Reference:- Click here

Try this

AtharvGoel (3)

@PattanAhmed I've tried using sockets previously to connect two repls. I've not had any success - repl seems to have some issue with it. I'll try again though. If you can create a working server-client socket, please comment it.

PattanAhmed (1411)

@AtharvGoel Oh...
Check this code and try:-

from flask import Flask
app = Flask('app')

@app.route('/')
def hello_world():
  return 'Hello, World!'

app.run(host='0.0.0.0', port=8080)
AtharvGoel (3)

@PattanAhmed I've used flask before, but don't know how to use it for my purposes. I can create a local webserver and stuff, but I don't know how to connect two repls.

PattanAhmed (1411)

@AtharvGoel Oh, I got what you are saying...
Repl.it can link two files each are in the same Repl.
Unfortunately, Repl.it cannot link two different Repls.
If you have two files named test1.py and service.py:-
test1.py

def some_func():
    print 'in test 1, unproductive'

if __name__ == '__main__':
    # test1.py executed as script
    # do something
    some_func()

service.py

import test1

def service_func():
    print 'service func'

if __name__ == '__main__':
    # service.py executed as script
    # do something
    service_func()
    test1.some_func()

Check this and try!

AtharvGoel (3)

@PattanAhmed So it's not possible? I don't want to communicate between files, but repls.

PattanAhmed (1411)

@AtharvGoel Oh,
Repls are not possible until now, I think.
Hopefully, they may add this feature.

But, Files in the Repl are possible as given the code above

AtharvGoel (3)

@PattanAhmed Technically, my question was never answered, but fine.

AtharvGoel (3)

@PattanAhmed I don't think you can run multiple files from the same repl. That's why I was asking for two different repls.

1927829 (0)

Hi! I'm not very experienced in python, but this might work:
In one real, we can type
from replit import db
x = str(input())
db["hello"] = x
and in the other repl:

db = To find the link, go to the first real and type $REPLIT_DATABASE_URL + "/hello"
import requests
response = requests.get(db)
print(response.text)
I hope that works.

1927829 (0)

@1927829 *repl and also type $REPLIT_DATABASE_URL in the shell.

Coder100 (18873)

You can use an iframe:

<iframe src="[url]"></iframe>

Replace [url] with the url of the repl.

AtharvGoel (3)

@Coder100 Isn't that html. I'd prefer to use python.

Coder100 (18873)

well, what do you want it to do? @AtharvGoel

Coder100 (18873)

you can only manipulate display with HTML. @AtharvGoel

AtharvGoel (3)

@Coder100 I don't want to create a display. In the repl.run s, one of them will use an input to take what the user says, and then send it to the other repl.run which will print it.