|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
最近闲的慌,于是用Python脚本把Python交互器给写了出来~~(说白了就是给IDLE套上了一个壳子)
- import code
- import sys
- def main():
- # 创建一个交互式解释器的实例
- interpreter = code.InteractiveConsole(locals=globals())
- print("Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32")
- print("Type:help, copyright, credits or license() for more information.")
- print('And you can close it by entering:exit()')
-
- while True:
- try:
- # 读取用户输入的代码
- user_input = input(">>> ")
- # 如果用户输入 'exit()',则退出
- if user_input.strip() == 'exit()':
- print('close Python')
- break
- # 执行用户输入的代码
- interpreter.push(user_input)
-
- except (EOFError, KeyboardInterrupt):
- # 处理文件结束符或中断
- print("\n close Python")
- break
- except Exception as e:
- # 捕捉并显示异常
- print(f"An error occurred: {e}")
- if __name__ == "__main__":
- main()
复制代码 |
评分
-
查看全部评分
|