0

Here is my code to run another python file

import pyautogui
from tkinter import *
import os
import webbrowser
from subprocess import *

root = Tk()
yes = open('Hello.py')
def Open():
    print(yes)

stup = Button(text='Stop', command=exit)
stup.pack()

g = Button(text='spam',command=Open,bg='red')
g.pack()

root.mainloop()

when I run the file it wont show me error but show me this

<_io.TextIOWrapper name='Hello.py' mode='r' encoding='cp1252'>

Idk what it mean so can someone correct me?

Timus
  • 10,974
  • 5
  • 14
  • 28
  • https://stackoverflow.com/questions/1186789/what-is-the-best-way-to-call-a-script-from-another-script Answered here. – pratham Dec 26 '20 at 12:59
  • 2
    Does this answer your question? [What is the best way to call a script from another script?](https://stackoverflow.com/questions/1186789/what-is-the-best-way-to-call-a-script-from-another-script) – JenilDave Dec 26 '20 at 13:26
  • `open()` is only for opening access to file - and later you can use `read()` to get data from file. And this way you could eventually run text from file using `eval()` but it may need better method. – furas Dec 26 '20 at 21:19

1 Answers1

0

I recommend using the runpy module:

import runpy

runpy.run_module("module_name")
Attila Viniczai
  • 644
  • 2
  • 8