Python作成仕様
2530 ワード
一、コード編成
二、文書の編成
三、スペース
四、注釈
五、ドキュメントの説明
六、命名規範
七、Main:スクリプトとして使用するファイルであっても、インポート可能であるべきである.
八、文字列:
九、その他
1. : 4
2. : 80
3. : , , 、 。
4. : , , :1. 。2. URL.3.
二、文書の編成
1. : -> -> -> ->
: -> ->
2.import: import ,
三、スペース
1. 、 、 , ( )
2. ( 、 、 )
3. "=" ,
4."," "#" "=" ,
四、注釈
, 。
, , , , , 。 , 。
1. : 。 "#" 。 "#" 。
2. , 。 .
3. . Python, .
五、ドキュメントの説明
1. 、 、 、 docstrings; , ( def )。
2. docstring ,
class SampleClass(object):
"""Summary of class here.
Longer class information....
Longer class information....
Attributes:
likes_spam: A boolean indicating if we like SPAM or not.
eggs: An integer count of the eggs we have laid.
"""
def __init__(self):
"""Inits SampleClass with blah."""
六、命名規範
1. ‘l’, ‘O’ 。
2. , ( lower_with_under.py).
3. , , 。
4. ( CapWords, Pascal )
5. , 。
6. , this_is_a_variable=1
7. , 。
8. ( ) , 。
9. self, cls。
10. (_) protected ( import * from ).
11. (__) .
七、Main:スクリプトとして使用するファイルであっても、インポート可能であるべきである.
(main functionality)
if __name__ == '__main__'
def main():
...
if __name__ == '__main__':
main()
八、文字列:
+ += , , .join
items = ['']
for last_name, first_name in employee_list:
items.append('' % (last_name, first_name))
items.append('%s, %s
')
employee_table = ''.join(items)
" " ,
九、その他
:
: , object ,
: ,try/except
sockets: sockets , , with