最好的python库_什么是最好的Python库模块框架代码?

Many python IDE's will start you with a template like:

print 'hello world'

That's not enough... So here's my skeleton code to get this question started:

My Module Skeleton, Short Version:

#!/usr/bin/env python

"""

Module Docstring

"""

#

## Code goes here.

#

def test():

"""Testing Docstring"""

pass

if __name__=='__main__':

test()

and,

My Module Skeleton, Long Version:

#!/usr/bin/env python

# -*- coding: ascii -*-

"""

Module Docstring

Docstrings: http://www.python.org/dev/peps/pep-0257/

"""

__author__ = 'Joe Author (joe.author@website.org)'

__copyright__ = 'Copyright (c) 2009-2010 Joe Author'

__license__ = 'New-style BSD'

__vcs_id__ = '$Id$'

__version__ = '1.2.3' #Versioning: http://www.python.org/dev/peps/pep-0386/

#

## Code goes here.

#

def test():

""" Testing Docstring"""

pass

if __name__=='__main__':

test()

Notes (PEP 8, UTF-8):

"""

===MODULE TYPE===

Since the vast majority of my modules are "library" types, I have constructed

this example skeleton as such. For modules that act as the main entry for

running the full application, you would make changes such as running a main()

function instead of the test() function in __main__.

===VERSIONING===

The following practice, specified in PEP 8, no longer makes sense:

__version__ = '$Revision: 1.2.3 $'

For two reasons:

(1) Distributed version control systems make it neccessary to include more

than just a revision number. E.g. author name and revision number.

(2) It's a revision number not a version number.

Instead, the __vcs_id__ variable is being adopted. This expands to, for

example:

__vcs_id__ = '$Id: example.py,v 1.1.1.1 2001/07/21 22:14:04 goodger Exp $'

===VCS DATE===

Likewise, the date variable has been removed:

__date__ = '$Date: 2009/01/02 20:19:18 $'

===CHARACTER ENCODING===

If the coding is explicitly specified, then it should be set to the default

setting of ASCII. This can be modified if necessary (rarely in practice).

Defaulting to UTF-8 can cause anomalies with editors that have poor unicode

support.

"""

Alternate Skeleton, Long Version:

(Code adapted from DasIch's answer.)

#!/usr/bin/env python

# -*- coding: ascii -*-

"""

package.module

~~~~~~~~~~~~~

A description which can be long and explain the complete

functionality of this module even with indented code examples.

Class/Function however should not be documented here.

:copyright: year by my name, see AUTHORS for more details

:license: license_name, see LICENSE for more details

"""

#

## Code goes here.

#

def test():

""" """

pass

if __name__=='__main__':

test()

There are a lot of PEPs that put forward coding style recommendations. Am I missing any important best practices? What is the best Python module skeleton code?

Update

Show me any kind of "best" that you prefer. Tell us what metrics you used to qualify "best".

解决方案#!/usr/bin/env python

# coding: utf-8

"""

package.module

~~~~~~~~~~~~~

A description which can be long and explain the complete

functionality of this module even with indented code examples.

Class/Function however should not be documented here.

:copyright: year by my name, see AUTHORS for more details

:license: license_name, see LICENSE for more details

"""

The module may or may not contain a main function so that's not part of the template.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值