Trying to create an object via a user's input

后端 未结 3 1277
隐瞒了意图╮
隐瞒了意图╮ 2021-01-07 15:36

I\'m trying to create an employee object via user input, but I\'m running into issues with my code. When I run this nothing happens and it\'s not throwing any e

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-07 16:28

    The reason this isn't running is because you've defined a class, but then there is nothing that is instantiating that class, so nothing happens when you run it.

    However, if you were to add that code to instantiate a class, say:

    e = employee()
    e.create_employee()
    

    you would run into errors caused by the circular nature of the code, as mentioned by @jonrsharpe.

    You could move create_employees outside of the class and have it be a wrapper which takes in input (into regular variables, or a dict, but not the class itself), and instantiates the object using that input. You could then call that function from the main part of the script.

    I would recommend reading through the Python doc on classes so you can become more familiar with the OO paradigm:

    https://docs.python.org/2/tutorial/classes.html

提交回复
热议问题