Python 脚本中心:轻松管理和运行你的脚本
以下是一个简单的 Python 脚本中心示例,帮助你轻松管理和运行你的脚本:
import os
print('Welcome to the Script Center!')
while True:
# 显示可用脚本
print('\nAvailable Scripts:')
scripts = os.listdir('scripts')
for i, script in enumerate(scripts):
print(f'{i+1}. {script}')
# 提示用户选择脚本
choice = input('\nPlease enter the number of the script you want to run (or 'q' to quit): ')
if choice.lower() == 'q':
break
try:
choice = int(choice)
script = scripts[choice-1]
# 运行脚本
os.system(f'python scripts/{script}')
except (ValueError, IndexError):
print('Invalid choice. Please try again.')
该脚本假设所有可用脚本都位于名为'scripts'的文件夹中。它使用 Python 的 os 模块列出所有可用脚本,并提示用户选择要运行的脚本。一旦用户做出选择,它将使用 os.system() 函数运行选定的脚本。
要使用此脚本中心,请将所有可用脚本放入名为'scripts'的文件夹中,并运行此脚本。
原文地址: https://www.cveoy.top/t/topic/jmDy 著作权归作者所有。请勿转载和采集!