简体   繁体   English

如何让我的 python 程序 (C-Bos) 只打开结尾带有“.bos.py”的文件?

[英]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.

相关问题 如何在没有.py文件位于源位置的情况下使程序移动文件 - How do I make my program move files without the .py file being in the source location 我有两个(.py)文件。 当第一个程序结束时,它将自行关闭,然后打开并运行第二个程序文件。 我该怎么做? - I have got two (.py) files. When the first program comes to end, it will close itself then open and run the second program file. How can ı do it? 如何在 Windows 10 上打开和查看 Python PY 文件? - How do I open and view Python PY files on Windows 10? 您需要将 EOS 和 BOS 代币放入自动编码器转换器中吗? - Do you need to put EOS and BOS tokens in autoencoder transformers? 如何使我的程序读取多个 txt 文件并将其创建为 dataframe for python? - How do I make it so that my program reads multiple txt files and creates it into a dataframe for python? Python - 如何使我的其他程序仅在 if 语句一致时执行? - Python - How do I make it so that my other program only executes when an if statement is in agreement? Discord.py 和网络浏览器 | 如何使 web 浏览器仅对消息的作者打开? - Discord.py and Webbrowser | How do I make the web browser open for only the author of the message? 我如何使我的程序进入python中的下一个elif - How do i make my program move on to the next elif in python 在使用py2exe编译python程序时如何使用我的图标? - How do I use my icons when compiling my python program with py2exe? 我如何使我的python程序在精美的窗口中执行 - How do i make my python program execute in a fancy window
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM