0

I am creating an code editor but when use input() code in inside my own code editor and try to run my terminal shows this error

error:-

Enter any number

Traceback (most recent call last):

  File "D:\coding notes\pytho project\editor\new.py", line 1, in <module>

    T = int(input("Enter any number\n"))

EOFError: EOF when reading a line

What modification I have to do So that my run function works correctly

this is my run function:-

def Run(event=None):
    global file
    if file == "":
        pass
    else:
        command = f'python "{file}"'
        run_file = subprocess.Popen(command,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
        Output, error = run_file.communicate()
        output.insert(END,f"{file}>>\n")
        output.insert(END,Output)
        output.insert(END,error)

full code(not full code short version of real code):-


import subprocess
from tkinter import*
from tkinter.filedialog import askopenfilename
def Open(event=None):
    global file
    file = askopenfilename(defaultextension=".py",filetypes=[("Python Files","*.py")])
    if file == "":
        file = None
    else:
        editor.delete(1.0,END)
        with open(file,"r") as f:
            editor.insert(1.0,f.read())
def Run(event=None):
    global file
    if file == "":
        pass
    else:
        command = f'python "{file}"'
        run_file = subprocess.Popen(command,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
        Output, error = run_file.communicate()
        output.insert(END,f"{file}>>\n")
        output.insert(END,Output)
        output.insert(END,error)
root = Tk()
file = ""

editor = Text()
editor.pack()
output = Text(height=15)
output.pack()

root.bind("<Control-o>",Open)
root.bind("<Shift-Return>",Run)



root.mainloop()

You can see the error in this image, this is the code editor that I have created:- enter image description here

Coder
  • 92
  • 11
  • Which python version are you using? If Python 2, then [refer here](https://stackoverflow.com/a/20449433/14465779) – Kartikeya Mar 22 '22 at 14:32
  • When I have seen this error, it's because the code editor I'm using requires the input to be in `stdin` before running the code, instead of inputting during runtime. It expects something to be there, but there isn't (**E**nd **O**f **F**ile when reading a line) – kenntnisse Mar 22 '22 at 14:39
  • `input()` requires a *real* console/terminal. – acw1668 Mar 22 '22 at 15:46
  • So how can I create a console/terminal please – Coder Mar 22 '22 at 16:12

0 Answers0