On linux, using sublime text. os.system('clear')
should just clear the console window. os.system('cls')
for windows. But it's returning different from me.
在Linux上,使用崇高的文本。Os.system(‘Clear’)应该只清除控制台窗口。用于Windows的os.system(‘cls’)。但它回来的时候和我不一样。
code:
代码:
import os
clear = lambda: os.system('clear')
move_dict = {'rock': 1, 'paper': 2, 'scissors': 3}
user1 = input('Rock, paper or scissors: ').lower().strip()
user1_x = move_dict.get(user1)
clear()
user2 = input('Rock, paper or scissors: ').lower().strip()
user2_x = move_dict.get(user2)
clear()
diff = user1_x - user2_x
if diff in [-1, 2]:
print(f'Player 1\'s {user1} loses. Player 2\'s {user2} wins.')
elif diff in [1, -2]:
print(f'Player 1\'s {user1} wins. Player 2\'s {user2} loses.')
else:
print(f'Both players chose {user1}, draw.')
returns:
退货:
Rock, paper or scissors: rock
TERM environment variable not set.
Rock, paper or scissors: scissors
TERM environment variable not set.
Player 1's rock wins. Player 2's scissors wins.
why is "TERM environment variable not set" returning when clear runs instead of just clearing the console?
为什么在Clear运行时返回“TERM环境变量未设置”,而不是只清除控制台?
tried defining the function using def instead of lambda, same error. didn't help. Previously asked similar questions don't lay out beginner friendly answers.
尝试使用def而不是lambda定义函数,同样的错误。没有用以前问过类似的问题,没有列出初学者友好的答案。
更多回答
@stark using SublimeREPL to run my code already, but did try with the method mentioned on there. Doesn't take inputs.
@stark已经使用SublimeREPL运行了我的代码,但确实尝试了上面提到的方法。不接受输入。
Somehow TERM
is not defined in sublime, can you define it as xterm-256color
which is the norm in most linuxes.
不知怎么的,术语在崇高中没有定义,你能把它定义为xTerm-256颜色吗?这是大多数线条中的标准。
@Philippe set term to xterm -256color and is now working, thank you.
@Philippe将Term设置为xTerm-256颜色,现在正在工作中,谢谢。
优秀答案推荐
interesting, os.system('clear')
works for me totally fine. I had to os.system('unset TERM; clear')
to reproduce your error.
有趣的是,os.system(“lear”)对我来说运行得很好。我不得不使用os.system(‘未设置的术语;清除’)来重现您的错误。
Most likely your TERM env is somewhere unset, uninherited when you get to your python script
您的术语env很可能在某个未设置的位置,当您使用您的python脚本时,它不会被继承。
the simplest way is to os.system('TERM=xterm-256color clear')
you can replace xterm-256color
with whatever is supported by your terminal
最简单的方法是使用os.system(‘Term=xTerm-256 COLOR Clear’),您可以用您的终端支持的任何内容替换xTerm-256 COLOR
更多回答
我是一名优秀的程序员,十分优秀!