简体   繁体   中英

How do you make python file run another python file

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?

I recommend using the runpy module:

import runpy

runpy.run_module("module_name")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM