私はここでできる限り答えようとします:
- あなたが求めているのは変数変数名です-これはPythonにはありません。(私はそれがVB.Netにあると思いますが、私をそれに拘束しないでください)
ユーザーは、新しいユーザーを作成し、名前、給与、役職を割り当てることができるターミナルメニューを取得します。そのオブジェクトをどのようにインスタンス化し、後でそれを管理したり、関数を呼び出したりする場合は、それを呼び出しますか?ここのデザインパターンは何ですか?
これは私が新しい人を追加する方法です(ミッキー-マウスの例):
# Looping until we get a "fin" message
while True:
print "Enter name, or "fin" to finish:"
new_name = raw_input()
if new_name == "fin":
break
print "Enter salary:"
new_salary = raw_input()
print "Enter position:"
new_pos = raw_input()
# Dummy database - the insert method would post this customer to the database
cnn = db.connect()
insert(cnn, new_name, new_salary, new_pos)
cnn.commit()
cnn.close()
では、データベースから人を取得したいとします。
while True:
print "Enter name of employee, or "fin" to finish:"
emp_name = raw_input()
if emp_name == "fin":
break
# Like above, the "select_employee" would retreive someone from a database
cnn = db.connect()
person = select_employee(cnn, emp_name)
cnn.close()
# Person is now a variable, holding the person you specified:
print(person.name)
print(person.salary)
print(person.position)
# It's up to you from here what you want to do
これは基本的な大まかな例ですが、私が言っていることは理解できると思います。
また、ご覧のとおり、ここではクラスを使用していません。このようなクラスは、ほとんどの場合、より良いアイデアですが、これは、実行時に変数を変更して使用する方法を示すためだけのものです。