- OS module的简单使用
# 取得当前文件的位置
path=os.path.realpath(__file__)
# path=os.path.abspath(__file__)
# 文件夹名, 文件名
os.path.dirname(path)
os.path.basename(path)
# 也可以直接获取当前文件夹
os.path.realpath("./")
# os.path.abspath("./")
a). os.getcwd()和os.path.realpath(file)的区别 link
b). realpath和abspath的区别 link
- zip的使用
a = [1,2,3]
b = [4,5,6]
c = [4,5,6,7,8]
zipped = zip(a,b) # 打包为元组的列表
[(1, 4), (2, 5), (3, 6)]
zip(a,c) # 元素个数与最短的列表一致
[(1, 4), (2, 5), (3, 6)]
zip(*zipped) # 与 zip 相反,*zipped 可理解为解压,返回二维矩阵式
[(1, 2, 3), (4, 5, 6)]
# 通过zip函数将两个序列压成字典
items2 = dict(zip(['a', 'b', 'c'], '123'))
- 判断key存在吗
if id in dict.keys():
- map和lambda的使用
info = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
a = map(lambda x:x+1,info)
print([*a]) #[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
-
numpy.savez_compressed
Numpy中数据的常用的保存与读取方法 -
openslide的使用 link
import openslide
slide = openslide.OpenSlide('filename‘)
slide.close()
小方法
import sys
sys.path.append(’引用模块的地址')
- argarse.ArgumentParser.parse_known_args() link
FLAGS, unparsed = parser.parse_known_args() #unparsed保存多余参数
- python3 限定方法参数
def test(a:int, b:str) -> str:
print(a, b)
return 1000
if __name__ == '__main__':
test('test', 'abc')
- *_的使用
*_ to express no interest in any further arguments
import numpy as np
arr_1d_bigger = np.arange(24)
arr_3d = arr_1d_bigger.reshape((2, 3, 4))
print(arr_3d)
arr = arr_3d.transpose(0,2,1)
print(arr)
6. Python 软件项目文件结构组织
PYTHON入门
Python - Error Type
Python | Accessing index and value in list
使用__slots__
如何学习Python爬虫[入门篇]?
笨办法学python
笨办法学python视频
本文介绍了Python中的OS模块使用,包括获取文件路径、目录操作等;讲解了ZIP函数的打包与解包;探讨了Numpy的savez_compressed方法进行数据保存;提到了openslide库在处理数字病理切片中的应用;还分享了一些Python编程中的小技巧,如指定脚本解释器、添加路径到环境变量、argparse模块的使用等。
933

被折叠的 条评论
为什么被折叠?



