我开发了一套简单的基于多语言控制台的计算器,我的问题是,在第一次执行时,当用户选择他的语言时,他将获得两倍于软件标题的信息。
------------------------------------------------------
Trooper Math Suite - ver. 0.1.5.1
------------------------------------------------------
Choose your default language:
------------------------------------------------------
1. English
2. Português Brasileiro
3. Español
------------------------------------------------------
You: 1
------------------------------------------------------
Trooper Math Suite - ver. 0.1.5.1
------------------------------------------------------
Select the calculator:
------------------------------------------------------
1. Biquadratic Equations Calculator
2. Pythagorean Theorem Calculator
------------------------------------------------------
You:
启动器的代码是:
# tms.py - launcher
ver = "0.1.5.1"
sep = "-" * 54
print(sep)
print("Trooper Math Suite - ver. {0}".format(ver))
print(sep)
try:
from config import *
if default_lang == "1":
print("""Select the calculator:\n{0}
1. Biquadratic Equations Calculator
2. Pythagorean Theorem Calculator\n{0}""".format(sep))
go = input("You: ")
print(sep)
if go == "1": import bc
elif go =="2": import pc
if default_lang == "2":
print("""Selecione a calculadora:\n{0}
1. Calculadora de Equações Biquadradas
2. Calculadora do Teorema de Pitágoras\n{0}""".format(sep))
go = input("You: ")
print(sep)
if go == "1": import bc
elif go =="2": import pc
if default_lang == "3":
print("""Seleccione la calculadora:\n{0}
1. Calculadora de Ecuaciones Bicuadráticas
2. Calculadora de Teorema de Pitágoras\n{0}""".format(sep))
go = input("You: ")
print(sep)
if go == "1": import bc
elif go =="2": import pc
except:
print("""Choose your default language:\n{0}
1. English
2. Português Brasileiro
3. Español\n{0}""".format(sep))
language=input("You: ")
while language != "1" and language != "2" and language != "3":
print(sep)
print("You must choose between 1, 2 or 3.")
print(sep)
language=input("You: ")
file = open("config.py", "w")
file.write('default_lang = "{0}"\n'.format(language))
file.close()
import tms
我用谷歌搜索过,人们建议使用 def lang() 之类的函数,但我不能这样做,因为:
SyntaxError: import * only allowed at module level