私はUserクラスを作成しています。このクラスの内部には、データの入力を求めるメソッドを作成します。 populate()メソッドでのinitパラメータを有効な値として使用するにはどうすればよいですか?ここで同じクラス内のメソッドの引数としてクラスパラメータを使用する
は私のコードです:
class User:
def __init__(self, last_name, first_name, social, rep_code, data_source):
self.last_name = last_name
self.first_name = first_name
self.social = social
self.rep_code = rep_code
self.data_source = data_source
def populate(self):
#prompt for user info and write to file
this.last_name = input("Please enter user last name:\n")
this.first_name = input("Please enter user first name:\n")
this.social = input("Please enter user social security number:\n")
this.rep_code = input("Please enter user rep code:\n")
this.data_source = input("Please choose the Data Source. Enter 6 for
NFS, 1 for DST, 2 for DAZL:\n")
そして、私は(user1.populateとして、この方法を実行したい)
はありがとうございます。
私はあなたがほとんどだと思いさておき移入 'で' self.'() ''にthis.'を変更するから、それを持っています。 – heyiamt
ありがとう、私は入力メソッドinside__init__を持つことができますか? –
どのクラスパラメータですか?インスタンス属性のみが表示されます。 https://docs.python.org/3/tutorial/classes.html#a-first-look-at-classes – wwii