简体   繁体   English

你如何让 python 文件运行另一个 python 文件

[英]How do you make python file run another python file

Here is my code to run another python file这是我运行另一个 python 文件的代码

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'> <_io.TextIOWrapper 名称='Hello.py' 模式='r' 编码='cp1252'>

Idk what it mean so can someone correct me?我知道这是什么意思,有人可以纠正我吗?

I recommend using the runpy module:我推荐使用runpy模块:

import runpy

runpy.run_module("module_name")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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