终端上的Python 3与shell不同?

Uns*_*yte -1 python shell terminal

我在python中构建了一个简单的文本游戏来向朋友展示,它在shell上运行良好但在终端中出错.在python中编译终端vs shell是否有区别?

在shell中,这是发生的事情: test是无效输入,因此它会要求您键入其中一个答案,然后在键入yes时继续

但在终端,它给了我这个错误: 在此输入图像描述

这有什么理由吗?

我的代码:

"""""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~IMPORT PACKAGES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""""

from random import randint
import os
import copy
import math
import time
import pickle
import platform
import subprocess as sp

"""""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~LOAD DATA/NEW GAME~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""""

newData = {"assassin" : {'hp' : 100, 'atk' : 250, 'lvl' : 1, 'arm' : 0, 'pow' : {'name' : 'surprise attack', 'lvl' : 0}, 'xp' : 0},
                             "mage" : {'hp' : 100, 'atk' : 200, 'lvl' : 1, 'arm' : 0, 'pow' : {'name' : 'fire','lvl' : 0}, 'xp' : 0},
                             "knight" : {'hp' : 100, 'atk' : 150, 'lvl' : 1, 'arm' : 10, 'pow' : {'name' : 'dodging','lvl' : 0}, 'xp' : 0},
                             "healer" : {'hp' : 500, 'atk' : 50, 'lvl' : 1, 'arm' : 0, 'pow' : {'name' : 'healing','lvl' : 0}, 'xp' : 0}}


if platform.system()=='Windows':
    file = 'filepath'
elif platform.system()=='Darwin':
    file = 'filepath'

"""Clears screen"""
clear = lambda: os.system('cls' if platform.system()=='Windows' else 'clear')

print('Load data?')

while True:
    answer = input()


    if answer == 'yes':
        load_file = open(file, 'rb')
        characterData = pickle.load(load_file)
        load_file.close()
        break
    elif answer == 'no':
        print('Starting a new game...')
        time.sleep(0.5)
        characterData = copy.deepcopy(newData)
        save_file = open(file, 'wb')
        pickle.dump(characterData, save_file)
        save_file.close()
        break
    else:
        print('That input cannot be deciphered. Please type "yes" or "no".')
Run Code Online (Sandbox Code Playgroud)

Ror*_*ton 5

看起来你在shell中使用Python 3.x但是在终端中使用了Python 2.x. 该input()函数在两个版本的Python中表现不同.

只需确保您在终端中使用Python 3.x. 如果您希望Python 2.x两次,请更改input()raw_input().