Python script header

后端 未结 6 1903
名媛妹妹
名媛妹妹 2020-12-04 10:54

The typical header should be

#!/usr/bin/env python

But I found below also works when executing the script like $python ./my_script.p

6条回答
  •  暖寄归人
    2020-12-04 11:09


    I'd suggest 3 things in the beginning of your script:

    First, as already being said use environment:

    #!/usr/bin/env python
    

    Second, set your encoding:

    # -*- coding: utf-8 -*-
    

    Third, set some doc string:

    """This is a awesome
        python script!"""
    

    And for sure I would use " " (4 spaces) for ident.
    Final header will look like:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    """This is a awesome
            python script!"""
    


    Best wishes and happy coding.

提交回复
热议问题