python常用编写格式和规范

0.目录格式

列举了几种常用写法,深度学习各种模型常用3中方法,

#1:
VIS/
|-- bin/
|   |-- vis
|
|-- vis/
|   |-- tests/
|   |   |-- __init__.py
|   |   |-- test_main.py
|   |
|   |-- __init__.py
|   |-- main.py
|
|-- docs/
|   |-- conf.py
|   |-- config.json
|
|-- setup.py
|-- requirements.txt
|-- README

#2.
VIS/
|-- src/
|   |-- util/
|   |   |-- __init__.py
|   |   |-- process.py
|   |   |-- frame2video.py 
|   |
|   |-- __init__.py
|   |-- main.py
|
|-- cfg/
|   |-- config.json
|
|-- setup.py
|-- requirements.txt
|-- README

#3.深度学习常用
├─caffe-fast-rcnn
├─data
│  ├─demo
│  └─scripts
├─experiments
│  ├─cfgs
│  ├─logs
│  └─scripts
├─lib
│  ├─datasets
│  │  ├─tools
│  │  └─VOCdevkit-matlab-wrapper
│  ├─fast_rcnn
│  ├─nms
│  ├─pycocotools
│  ├─roi_data_layer
│  ├─rpn
│  ├─transform
│  └─utils
├─models
│  ├─coco
│  │  ├─VGG16
│  │  │  ├─faster_rcnn_end2end
│  │  │  └─fast_rcnn
│  │  └─VGG_CNN_M_1024
│  │      ├─faster_rcnn_end2end
│  │      └─fast_rcnn
│  └─pascal_voc
│      ├─VGG16
│      │  ├─faster_rcnn_alt_opt
│      │  ├─faster_rcnn_end2end
│      │  └─fast_rcnn
│      ├─VGG_CNN_M_1024
│      │  ├─faster_rcnn_alt_opt
│      │  ├─faster_rcnn_end2end
│      │  └─fast_rcnn
│      └─ZF
│          ├─faster_rcnn_alt_opt
│          ├─faster_rcnn_end2end
│          └─fast_rcnn
└─tools
1.默认python路径声明

第一行大部分python文件的头部都会写上 #!/usr/bin/python 或者 #!/usr/bin/env

#!/usr/bin/env python

普通运行模式例如(linux) : python .py 第一行语句无效。
可执行模式:./
.py (文件要有可执行权限chmod a+x *.py),第一行语句为脚本语言指定解释器。
注:
#!/usr/bin/env python 是找系统 PATH 中指定的第一个 python 来执行你的脚本,比如虚拟环境设为第一个。
#!/usr/bin/python 是找系统默认 python 环境,但是大家普遍不爱用默认的。

2.编码

第二行一般设置编码

# _*_ coding:utf-8 _*_
  • 如果没有此文件编码类型的声明,则 python 默认以ASCII编码去处理;如果你没声明编码,但是文件中又包含非ASCII编码的字符的话,python解析器去解析的 python 文件就会报错。
  • 必须放在python文件的第一行或第二行;
  • 支持的格式有三种:(一般用2)
# coding=<encoding name>
最常见的,带冒号的(大多数编辑器都可以正确识别的):
#!/usr/bin/python
# -*- coding: <encoding name> -*-
vim的:
#!/usr/bin/python
# vim: set fileencoding=<encoding name> :
3.版权声明

以下是几个实例,来自github等

#1
 *Copyright: Copyright (c) 2017
 *Created on 2019-6-6
 *Author: kobe
 *Version 1.0 
 *Title: a simple implement of faster-rcnn

#2.
/* Generated by kobe 0.20.1 on Wed Oct  5 13:15:30 2016 */

#3.
# --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------


#4.
# --------------------------------------------------------
# Pytorch multi-GPU Faster R-CNN
# Licensed under The MIT License [see LICENSE for details]
# Written by Jiasen Lu, Jianwei Yang, based on code from Ross Girshick
# --------------------------------------------------------
4.编码风格

命名规范: https://www.cnblogs.com/Maker-Liu/p/5528213.html
Google python风格: https://zh-google-styleguide.readthedocs.io/en/latest/google-cpp-styleguide/comments/

  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值