在Mac上执行Python的os.system 找不到clear的路径
环境:MacBook Pro + PyCharm
想要在python中实现os.system('clear')
然而终端显示TERM environment variable not set.
网上查了似乎要加open,类似于os.system('open clear'),然而却怎么也找不到clear的路径,因此求教
[经过版主编辑]
环境:MacBook Pro + PyCharm
想要在python中实现os.system('clear')
然而终端显示TERM environment variable not set.
网上查了似乎要加open,类似于os.system('open clear'),然而却怎么也找不到clear的路径,因此求教
[经过版主编辑]
不论执行哪条命令,都会显示TERM environment variable not set.
如果执行os.system('open /usr/bin/env clear'),倒是可以打开新的terminal.
我的代码如下:
def marquee(content):
while True:
os.system('/usr/bin/clear') # clear the screen
print(content)
content = content[-1] + content[:-1]
time.sleep(0.2) # sleep 0.4 second
if __name__ == "__main__":
str1 = 'Welcome to python…………'
marquee(str1)
如果执行os.system('open /usr/bin/env clear'),就会打开无数个terminal。
不加 open 的時候, os.system 相當於在新的 terminal 中只調用 clear, 但是調用的時候並沒有terminal
至於加了 open, 在 while True 的時候, 每次循環都會打開一個 terminal
如果 os.system('clear')想要生效的話, 你需要手動執行
python your_script.py
os.system('/usr/bin/env clear')
或者
os.system('/usr/bin/clear')
在Mac上执行Python的os.system 找不到clear的路径