私は外部のpyファイル内にdefファイルを作成しようとしています。.py内でのPythonの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
とその属性も含まれています。
私はあなたがこれを行う方法の道に私を導くことができ期待して、それが不可能な場合だけで言うと、私は私のプロジェクトを再考しますしてくださいました:)
質問ごとに新しい機能を作成する必要があると思われるのはなぜですか?各関数は同じデータを扱います。 *データだけを保存し、そのデータをロードして表示する* 1つの*関数を持っています。 –
[Pythonで動的関数を定義する]の可能な複製(http://stackoverflow.com/questions/3687682/python-define-dynamic-functions) – iCart