(记录一下遇到过的问题,做点笔记)
1、 from future import print_function的用法
用途:把python新版本中print_function函数的特性导入到当前版本。如,在python2环境下,使用此句,则可以超前使用python3的print函数了。只能放置于当前运行代码片段的最开头。否则会报错如下 “ SyntaxError: from future imports must occur at the beginning of the file”:
2、super(子类,self).要继承的父类函数()
3、python mask
python本身不能直接对列表使用mask
mask应该是对numpy的array使用的
且这里的mask其实是一个bool值array组
4、 list、tuple、np.array的尺寸属性
- list结构通过len(list)来得到其长度,其没有shape和size属性;
- numpy有size和shape,这两个的差别在于,size记录数组元素的个数,而shape记录数组的行数列数
5、 list 的append() 和extend()函数不同
- list.append()是在列表尾部加一个元素,不论参数是什么数据类型(列表、字符串等等)都被识别为一个元素。参数只有一个。
- list.extend()只接受一个列表作为参数,列表中的每个元素都被加到list尾部。
6、get_arguments()
def get_arguments():
parser = argparse.ArgumentParser(description="test")
parser.add_argument("-g",type=str,help="0;1;2",default="0",required=True)
return parse.parse_args()