GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Python/Article/codeSpecification/codeSpecification_third.md at master · khle08/Python

Expand file tree

/

codeSpecification_third.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
82 lines (56 loc) · 1.32 KB
/

codeSpecification_third.md

Copy path

File metadata and controls

82 lines (56 loc) · 1.32 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

三、命名规范

1、模块

  • 模块尽量使用小写命名,首字母保持小写,尽量不要用下划线(除非多个单词,且数量不多的情况)
# 正确的模块名
import decoder
import html_parser

# 不推荐的模块名
import Decoder

2、类名

  • 类名使用驼峰(CamelCase)命名风格,首字母大写,私有类可用一个下划线开头
class Farm():
    pass

class AnimalFarm(Farm):
    pass

class _PrivateFarm(Farm):
    pass
  • 将相关的类和顶级函数放在同一个模块里. 不像Java, 没必要限制一个类一个模块.

3、函数

  • 函数名一律小写,如有多个单词,用下划线隔开
def run():
    pass

def run_with_env():
    pass
  • 私有函数在函数前加一个下划线_
class Person():

    def _private_func():
        pass

4、变量名

  • 变量名尽量小写, 如有多个单词,用下划线隔开
if __name__ == '__main__':
    count = 0
    school_name = ''
  • 常量采用全大写,如有多个单词,使用下划线隔开
MAX_CLIENT = 100
MAX_CONNECTION = 1000
CONNECTION_TIMEOUT = 600

5、常量

  • 常量使用以下划线分隔的大写命名
MAX_OVERFLOW = 100

Class FooBar:

    def foo_bar(self, print_):
        print(print_)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.