我想创建一个def文件内的py文件是外部例如。蟒蛇def创建一个.py
calls.py
:
def printbluewhale():
whale = animalia.whale("Chordata",
"",
"Mammalia",
"Certariodactyla",
"Balaenopteridae",
"Balaenoptera",
"B. musculus",
"Balaenoptera musculus",
"Blue whale")
print("Phylum - " + whale.getPhylum())
print("Clade - " + whale.getClade())
print("Class - " + whale.getClas())
print("Order - " + whale.getOrder())
print("Family - " + whale.getFamily())
print("Genus - " + whale.getGenus())
print("Species - " + whale.getSpecies())
print("Latin Name - "+ whale.getLatinName())
print("Name - " + whale.getName())
mainwindow.py
:
import calls
import animalist
#import defs
keepgoing = 1
print("Entering main window")
while True:
question = input("Which animal would you like to know about?" #The question it self
+ animalist.lst) #Animal Listing
if question == "1":
print(calls.printlion())#Calls the animal definition and prints the characteristics
if question == "2":
print(calls.printdog())
if question == "3":
print(calls.printbluewhale())
'''if question == "new":
def new_animal():
question_2=input("Enter the name of the new animal :")'''
我所试图做的是question == new
将在calls.py
创建一个新的高清和我将能够名称添加到def
以及属性。
我希望你能带领我的如何做到这一点的一种方式,如果它是不可能的,请只是说,我会重新考虑我的项目:)
为什么你认为你需要为每个问题创建新的功能?每个功能都是一样的,只是数据不同;存储*只是数据*并具有加载和显示该数据的一个*函数。 –
[Python定义动态函数]的可能重复(http://stackoverflow.com/questions/3687682/python-define-dynamic-functions) – iCart