简体   繁体   English

在启动python shell时自动执行命令

[英]Automatically execute commands on launching python shell

I was wondering if there is a way to automatically run commands on entering the python shell as you would with the .bash_profile or .profile scripts with bash. 我想知道是否有一种方法可以自动运行命令进入python shell,就像使用bash的.bash_profile或.profile脚本一样。 I would like to automatically import some modules so I don't have to type the whole shebang everytime I hop into the shell. 我想自动导入一些模块,所以每次进入shell时我都不必输入整个shebang。

Thanks, 谢谢,

是的,你可以使用PYTHONSTARTUP环境变量来做到这一点所概述这里

Also consider using ipython if you're doing a lot of interactive work. 如果你正在进行大量的互动工作,也可以考虑使用ipython Your options for this kind of automation expand significantly. 您对此类自动化的选择显着扩展。

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

相关问题 Python - 如何使用管道执行 shell 命令,但没有“shell=True”? - Python - how to execute shell commands with pipe, but without 'shell=True'? 如何使用python打开adb shell并在shell中执行命令 - How to open adb shell and execute commands inside shell using python Python:我想使用python脚本执行shell命令 - Python: I want to execute shell commands using python script Python Popen-如何使用python在嵌套子shell中执行命令 - Python Popen - how to execute commands in nested sub shell using python 如何启动python shell并使用某些命令自动初始化它? - How can I start the python shell and automatically initialize it with some commands? Python无需打开终端即可执行Shell命令 - Python Execute Shell commands without having a terminal open 如何在Python中创建一个泛型方法来执行多个管道shell命令? - How to make a generic method in Python to execute multiple piped shell commands? 在 Python Paramiko 中的 SSH 服务器上的辅助 shell/命令中执行(子)命令 - Execute (sub)commands in secondary shell/command on SSH server in Python Paramiko 调用shell脚本后如何以编程方式(python)执行终端命令(控件将在shell脚本下) - how to programmatically(python) execute terminal commands after invoking shell script(control will be under shell script)) Python和Shell命令问题 - Python and Shell commands issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM