[英]How do I make my python program (C-Bos) open only files with ".bos.py" at the end?
So C-Bos has programs that are.py files obv and you can open them through the main program or just open them like any other.py file.所以 C-Bos 有 .py 文件 obv 的程序,你可以通过主程序打开它们,或者像打开任何其他 .py 文件一样打开它们。 And I want it to only recognize files with.bos.py at the end.
我希望它只识别最后带有 .bos.py 的文件。
I asked ChatGPT but they made it only open files called.bos.py lmao.我问过 ChatGPT,但他们只打开名为 .bos.py lmao 的文件。 Oh and when I tried to open files with that (I renamed a program to.bos.py lol) C-Bos just crashed.
哦,当我试图用它打开文件时(我将一个程序重命名为 .bos.py 哈哈),C-Bos 崩溃了。 I am using elif statements for this btw the code (that works) for that is:
我正在为此使用 elif 语句,顺便说一句,代码(有效)是:
elif(cmd=="Run"):
ope = input("file:")
subprocess.Popen(ope, shell=True)
So yeah end of post.所以是的帖子结束。
What about usibg glob
for this?为此使用 usibg
glob
怎么样? I don't understand what you meant by opening
(run it or open in notepad, idle) so I copied the subprocess
line.我不明白你所说的
opening
(运行它或在记事本中打开,闲置)是什么意思,所以我复制了subprocess
行。
import glob
import subprocess
for file in glob.glob("*.bos.py"):
subprocess.Popen(file, shell=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.