社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  0x5453  »  全部回复
回复总数  3
4 年前
回复了 0x5453 创建的主题 » 如何在Python中读取终端输出的第一行?

不要使用 os.system 。它无法从子进程捕获stdout/stderr。

而是使用 subprocess.run (或 subprocess 包装)。例如:

keyboard_check = subprocess.run(["pip", "show", "keyboard"], capture_output=True, text=True)
if keyboard_check.stdout.split('\n')[0] == "WARNING: Package(s) not found: keyboard":
    ...

或者,检查失败的更好方法是使用流程的返回代码。 pip show 返回 1 如果指定的包不存在。下面是它的样子:

keyboard_check = subprocess.run(["pip", "show", "--quiet", "keyboard"])
if keyboard_check.returncode != 0:
    ...

这样,您就不需要依赖于特定的错误消息,因此如果 pip 一旦改变了警告信息,你就不需要回来更新你的脚本了。

4 年前
回复了 0x5453 创建的主题 » PyCharm侧工具文件夹上的点

根据 PyCharm docs ,点表示文件夹是一个 包裹 .

查看文档 git commit ( git help commit ),当您添加 -m 标志,它希望下一个参数是提交消息。

-m <msg>, --message=<msg>
    Use the given <msg> as the commit message. If multiple -m options are given, their values are concatenated as separate paragraphs.

因此, git commit -am "$BR" " $1" 是不正确的,因为它会将您的分支名称解释为提交消息,然后将所有剩余的参数解释为某个路径说明符。

请改为:

function push(){
    local br=`branch | grep \* | cut -d ' ' -f2`
    git commit -a "$br" -m "$1"
    git push origin "$br"
}