master
mrxn27umf 5 years ago
parent 49436c9e74
commit e251d3eb00

@ -0,0 +1,165 @@
##### 项目代码:
Copyright (C) 2018 Google Inc.
#
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
#
http://www.apache.org/licenses/LICENSE-2.0
#
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#!/usr/bin/env bash
Exit when any command fails.
每一文件包含以下项,依次是:
###### 1) 版权copyright statement如Copyright 2008 Google Inc.
###### 2) 许可版本license boilerplate为项目选择合适的许可证版本如Apache 2.0 、BSD 、LGPL 、GPL
当我们使用github或者其它地方的开源项目时候需要注意开源项目的授权协议。
开源不等于免费使用,如果公司使用开源项目时候违反其开源协议,有可能给公司或者个人带来版权纠纷。
使用时候需要慎重阅读开源代码提供者的授权条件。
###### 指定解释器
不管在linux还是在windows下要运行一个python文件比如hello.py的方式一般都是
python ./hello.py。然而有一种方式可以直接运行hello.py文件那就是直接在python文件开头指定所使用的python解释器。然后就可以直接用./hello.py 运行了。在python文件开头指定解释器”的方式有两种。
###### 1.1. 直接指定解释器路径
#!/usr/bin/python
上面这种方式,指定了必须用/usr/bin/python这个解释器来解释本python文件。
当然了,也可以写成
#!/usr/local/python3/bin/python3.4
只要那个路径下有python解释器。
###### 1.2. 指定系统环境变量设定的解释器路径
#!/usr/bin/env python
而这种方式指定了使用linux环境变量$PATH里某个路径下名为python的解释器来解释本python文件。
(注意到开头/usr/bin/env是linux里读写环境变量的一个程序
如果环境变量$PATH的内容是/usr/bin:/usr/local/bin:/usr/local/python3/bin那么上面的注释就意味着会依序寻找这些路径
1. /usr/bin/python
2. /usr/local/bin/python
3. /usr/local/python3/bin/python
第一个存在的路径就会作为python解释器使用。
当然,如果写成这样
#!/usr/bin/env python3
那么查找释器的路径顺序就会变成
1. /usr/bin/python3
2. /usr/local/bin/python3
3. /usr/local/python3/bin/python3
2. 标明本py文件的编码类型比如GBK、UTF-8、UCS2之类。
##### 项目代码:
-*- coding: utf-8 -*-
Copyright 2018 Google LLC. All Rights Reserved.
#
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
#
http://www.apache.org/licenses/LICENSE-2.0
#
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
python文件第二行一般是下面两种之一
-*- coding: utf-8 -*-
或者
coding: utf-8
这一行的意思是告诉python解释器这个文件是以UTF-8方式编码存储的。其实类似文本文件开头的BOM。
对于全文都是ASCII编码的py文件而言这行注释一般没用因为ASCII字符在绝大多数编码存储方式中都是相同的除了UCS2这种
但是如果代码中出现了明文的中文、日文之类非ASCII的字符作为字符串常量或注释他们在不同编码存储方式下在硬盘上的字节流是不同的。
例如下面这段python代码
s = "函数"
如果不告诉Python解释器如何理解这个py文件就会出现乱码。
比如如果py文件实际上是以UTF-8方式存储的就是表格第二行但python解释器却以GBK编码存储去理解它那么这段代码就会出现乱码。那么用print(s) 打印字符串时,就会看到乱码文字了。
##### 项目代码:
def init(self, operating_system, architecture):
"""Constructs a new platform.
Args:
operating_system: OperatingSystem, The OS
architecture: Architecture, The machine architecture.
"""
self.operating_system = operating_system
self.architecture = architecture
Args:
```java
列出每个参数的名字, 并在名字后使用一个冒号和一个空格, 分隔对该参数的描述.如果描述太长超过了单行80字符,使用2或者4个空格的悬挂缩进(与文件其他部分保持一致).
```
##### 样例:
#!usr/bin/env python
-*- coding: utf-8 -*-
def is_prime(num):
"""
Args:
param num: 正整数
return: 是素数返回True不是素数返回False
"""
i = 2
while i < num:
r = num % i
if r == 0:
return False
i += 1
return True
Loading…
Cancel
Save