随笔分类 -  python

摘要:问题 用法 配合递归使用,遍历树形结构比较方便 E.g: def parse(tree): global count count += 1 for subtree in tree: label = subtree.label() if label == 'OrderBy': print(f"###: 阅读全文
posted @ 2021-10-13 20:37 春树&暮云 阅读(24) 评论(0) 推荐(0) 编辑
摘要:问题 字典中包含非字典的子对象的序列化 方式1 使用default参数,default=lambda obj: obj.__dict__(), 保证其中包含的非字典对象的类有方法__dict__ class ID(object): def __init__(self, id) -> None: se 阅读全文
posted @ 2021-10-13 18:52 春树&暮云 阅读(133) 评论(0) 推荐(0) 编辑
摘要:常用命令 env conda env list # 查看虚拟环境 conda create -n python2 python=2.7 anaconda ## 创建虚拟环境 常见问题 conda: command not found ~/.bashrc 添加环境变量 export PATH=$PAT 阅读全文
posted @ 2021-10-11 14:33 春树&暮云 阅读(18) 评论(0) 推荐(0) 编辑
摘要:问题 服务器端开启jupter-notebook,并且只允许localhost方式启动,本机如何访问远程服务器的jupter? 方法 Using SSH Tunneling Using Reverse Proxy 详情参考 访问远程jupter-notebook 阅读全文
posted @ 2021-09-30 14:58 春树&暮云 阅读(39) 评论(0) 推荐(0) 编辑
摘要:问题 from .duckling import Duckling >>> ImportError: numpy.core.multiarray failed to import 解决方法 numpy版本和duckling不兼容,需要版本匹配,卸载numpy,重新安装numpy 解决 以下版本验证兼 阅读全文
posted @ 2021-09-30 13:56 春树&暮云 阅读(73) 评论(0) 推荐(0) 编辑
摘要:问题 针对一个字符串按特定模式,比如数字、字母、表情符等分割 方法 使用python的re库 import re re_han = re.compile("([\u4E00-\u9FD5a-zA-Z0-9+#&\._%\-]+)", re.U) re_eng = re.compile('[a-zA- 阅读全文
posted @ 2021-09-30 10:34 春树&暮云 阅读(392) 评论(0) 推荐(0) 编辑
摘要:import路径 python aa.py # 默认将aa.py文件所在路径(非当前执行路径)添加到系统路径sys.path,并且aa中引用的其他模(从当前执行路径为root_path引用的包和模块) 可以正常导入 python xxx/aa.py # aa.py从当前执行路径为root_path引 阅读全文
posted @ 2021-09-26 17:57 春树&暮云 阅读(37) 评论(0) 推荐(0) 编辑
摘要:魔法函数 __str__ vs __repr__ __str__是类实例化后。print(cls)触发调用,本质是print=>str=>str 调用 __repr__ 开发模式下,直接输出cls,会触发__repr__调用 __getitem__、__setitem__、__delitem__ 分 阅读全文
posted @ 2021-09-17 17:11 春树&暮云 阅读(51) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示