[英]Python 3 on Terminal different from shell?
我用python構建了一個簡單的文本游戲來向朋友展示,它在shell上運行良好,但在終端上出錯。 在python中為Terminal vs Shell進行編譯有區別嗎?
有什么理由嗎?
我的代碼:
"""""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~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".')
看起來您在外殼中使用Python 3.x,但在終端中使用Python2.x。 input()
函數在兩個Python版本中的行為有所不同。
只要確保您在終端中使用Python3.x。 如果兩次都需要Python 2.x,請將input()
更改為raw_input()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.