
Google Python Style Guide
补充单下划线_xxx开头:表示受保护的内部变量或函数,除非__all__=[‘内部变量1’,’内部变量2 ’]中有,否则import时不会导入这些内部变量
类中双下划线__xxx开头:表示私有属性或方法,__xxx编译时会被改写_类名__xxx即真正调用的方法名字已被改变,前加上了_类名
小写,下划线连接
变量 局部变量小写,下划线连接
全局变量小写,下划线连接
公共全局变量:public_variable
保护全局变量:protected_variable
大写,下划线连接
公共常量:PUBLIC_CONST
保护常量:PROTECTED_CONST
驼峰法
公共类:Public_Class
保护类:_Protected_Class
小写,下划线连接
保护属性:_protected_property
私有属性:__private_property
小写,下划线连接
保护方法:_protected_funcname
私有属性:__private_funcname
小写,下划线连接
公共模块:public_module
保护模块:_protected_module
小写,下划线连接
注释规范 TODO#TODO(name contact): comment
#TODO(xcrj xxx@163.com): Test this function, at next week
导包规范
规范:不同部分使用空格隔开
基础包
第三方包
工具包
例子
import collections
import queue
import sys
from absl import app
from absl import flags
import bs4
import cryptography
import tensorflow as tf
from book.genres import scifi
from myproject.backend.hgwells import time_machine
from myproject.backend.state_machine import main_loop
from otherproject.ai import body
from otherproject.ai import mind
from otherproject.ai import soul
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)