What is the EAFP principle in Python?

前端 未结 3 1458
自闭症患者
自闭症患者 2020-11-21 22:44

What is meant by \"using the EAFP principle\" in Python? Could you provide any examples?

3条回答
  •  南方客
    南方客 (楼主)
    2020-11-21 23:06

    I call it "optimistic programming". The idea is that most times people will do the right thing, and errors should be few. So code first for the "right thing" to happen, and then catch the errors if they don't.

    My feeling is that if a user is going to be making mistakes, they should be the one to suffer the time consequences. People who use the tool the right way are sped through.

提交回复
热议问题