我试图在py文件中创建一个def文件
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,并且我将能够为def
和属性添加一个名称。你知道吗
我希望你能引导我找到一个方法来做这件事,如果这是不可能的,请说,我会重新考虑我的项目:)
你想在这里做的似乎是一个解决办法,至少在你试图处理它的方式。你知道吗
如果我正确地理解了这个问题,那么您正在尝试创建一个python脚本,该脚本接受用户的输入,如果该输入等于“new”,那么就让它能够定义一个新的动物名称。你知道吗
你目前正在使用大量的手工工作来处理这个问题,这将是非常难以扩展的,特别是考虑到你可能正在处理的数据集的大小(整个动物王国?)。你知道吗
你可以试着这样处理:
使用字典定义数据集:
这将建立您的数据集。假定每个
whale
类实例(如果有)都从执行所有打印的假定Animal
类继承属性,例如:然后你就可以上鲸鱼课了:
现在有了打印数据的方法。你知道吗
排除这些问题后,您可以继续添加输入: 在你的主.py地址:
除此之外,值得一提的是,如果您使用dict和数组,您可以将内容放入数据库,并从中提取数据。你知道吗
希望这有帮助:)
相关问题 更多 >
编程相关推荐