【Python】相关语法知识点

写python过程中常用的一些语法,数据结构等等积累。
不断补充..

1. 编码问题

unicode和string
unicode转string:

str.encode("utf-8")

string转unicode

unicode(str,"utf-8")

2. 文件路径

1) 绝对路径和相对路径

#绝对转相对
print os.path.relpath("/User/Lychee/my_pictures/a0.txt")
#../my_pictures/a0.txt

#相对转绝对
path = "./my_pictures/a0"
print os.path.abspath(path)
#/User/Lychee/my_pictures/a0.txt

2)文件路径

#取文件夹下所有文件
path = './my_pictures'
image_paths = [os.path.join(path, f) for f in os.listdir(path)]

3. 对复杂数据结构排序(参考链接博客)

你可能感兴趣的:(数据结构,python)