文章分类 -  代码实例

摘要:##常用字符串操作 # 去除空格 "test string ".strip() # 去除字符串前导、后缀的指定字符 " test string ".strip("-") # 子字符串出现次数 " test string ".count("-") # 子字符串首次出现的位置,返回结果为 Base 0, 阅读全文
posted @ 2024-01-16 06:16 汉学 阅读(29) 评论(0) 推荐(0)
摘要:通用的 try 语句 try: ... except Exception as r: print(r) 获取当前脚本所在路径及脚本名称 import sys # sys.path[0] 返回当前脚本所在路径,形如“c:\users\aa”,末尾不含反斜线 path = sys.path[0] # s 阅读全文
posted @ 2020-07-27 06:24 汉学 阅读(848) 评论(0) 推荐(0)