0

我对 python 很陌生,我有这样的代码:

os.system(''' PROMPT_COMMAND="printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -" ''')

那个部分:

PROMPT_COMMAND="printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -"

确实打印-以填充外壳宽度。上述命令在命令提示符下按预期工作。但是当我在python中做的时候。我根本没有输出。

4

2 回答 2

2

There is no point of issuing this command at all.

As I understand it, you are just setting the environment variable PROMPT_COMMAND in order to make the shell execute it on every prompt.

But setting an environment variable has only an impact of a called shell, but not to the caller. You cannot change the environment of your parent process.

于 2013-04-19T07:32:47.630 回答
-2

这会做。正如我所看到的,问题在于引号:

import os

PROMPT_COMMAND = 'printf "%*s\n" "${COLUMNS:-$(tput cols)}" "" | tr " " -'
os.system(PROMPT_COMMAND)
于 2013-04-19T07:18:10.207 回答