Does python have a “use strict;” and “use warnings;” like in perl?

后端 未结 6 1538
刺人心
刺人心 2021-02-02 05:27

I am learning perl and python... at the same time, not my by design but it has to be done.

Question:

In a perl script I use(see below) at the head of my txt.

6条回答
  •  一整个雨季
    2021-02-02 06:13

    Not a compile-time error, but Python has many linters that can identify the same type of errors as Perl's "use strict":

    Consider a Python file named tmp.py with:

    def foo():
        a = 1
        b = 2
        return a
    

    flake8 tmp.py will return:

    tmp.py:13:5: F841 local variable 'b' is assigned to but never used
    

    In addition to flake8, check out mypy for more advanced type checking and pylint to enforce certain coding styles. As with any programming language, nothing prevents you from using multiple linters on your codebase -- in fact it's encouraged as each linter has a different focus.

提交回复
热议问题