随笔分类 -  Python & Jython

摘要:测试环境,假设: 主文件绝对路径:/home/ubu/py_test/main.py 模块文件:/home/ubu/py_test/con.py 模块目录:/home/ubu/py_test/modules/tt.py 模块目录:/home/ubu/py_test/modules/test/t1.p 阅读全文
posted @ 2022-12-16 11:05 悟透 阅读(1498) 评论(0) 推荐(0) 编辑
摘要:方式一: import sys, getopt if ( __name__ == '__main__' ) or ( __name__ == 'main' ) : ## 参数0 是文件名+后缀 ## 参数一 Name = sys.argv[1]; ## 参数二 age = sys.argv[2]; 阅读全文
posted @ 2022-12-12 12:27 悟透 阅读(2811) 评论(0) 推荐(0) 编辑
摘要:替换字典值,路径中的符号 >>> a={"cover": "cover_images\\test.png"} >>> >>> a=eval(str(a).replace("\\\\","/")) >>> >>> print(a) {'cover': 'cover_images/test.png'} 阅读全文
posted @ 2022-12-11 20:20 悟透 阅读(304) 评论(0) 推荐(0) 编辑
摘要:问题: 如何将两个数字拼接 解决方法:将整形数字转成字符串拼接后,在转回整形。 >>> a = 1 >>> b = 2 >>> c = str(a) + str(b) >>> print(int(c)) 12 阅读全文
posted @ 2022-12-02 23:33 悟透 阅读(444) 评论(0) 推荐(0) 编辑
摘要:错误:NameError: name 'getopt' is not defined 原因:没有引入模块,脚本里添加下面内容 import getopt 错误:NameError: name 'argv' is not defined 原因:没有给 main() 函数传入 argv 参数。即便多次跳 阅读全文
posted @ 2022-12-02 14:39 悟透 阅读(242) 评论(0) 推荐(0) 编辑
摘要:功能:python 脚本登陆邮箱 查找 指定邮件。 代码: #!/usr/bin/env python #-*- coding:UTF-8 -*- # # pythont version: 3.8.8 ## 导入模块 import imaplib,string,os,email from email 阅读全文
posted @ 2022-10-31 11:22 悟透 阅读(1268) 评论(0) 推荐(0) 编辑
摘要:问题: Python xlrd模块读取xls文件,提示 TypeError: sequence item 4: expected str instance, float found 原因: 正常表格里内容读取后,存放到Python列表(list)里,要么是整数,要么是字符串。 而错误提示最后显示“  阅读全文
posted @ 2022-07-29 09:39 悟透 阅读(1061) 评论(0) 推荐(0) 编辑
摘要:风格一: 来源:https://www.jianshu.com/p/e266137ebca0 方法里,每个空行分割成段,每段功能简介,都写在开头注释中,段介绍以:开头 # coding=utf-8 import pymysql from tool.read_config import ReadCon 阅读全文
posted @ 2022-05-04 13:13 悟透 阅读(39) 评论(0) 推荐(0) 编辑
摘要:python头和导入pymysql模块: #!/usr/bin/python # -*- coding: UTF-8 -*- import pymysql 打开数据库: 写法一:推荐 db=pymysql.connect(host='192.168.83.144',user='user1',pass 阅读全文
posted @ 2022-04-30 17:56 悟透 阅读(185) 评论(0) 推荐(0) 编辑
摘要:编程语言的参数: argc表示参数的个数, argv存放着具体的参数, argv[0]指向程序本身, argv[1]指向第一个参数, argv[2]指向第二个参数, ..., argv[argc]存放0 表示结束。 来源: https://mp.weixin.qq.com/s/oRtXzf1HsHs 阅读全文
posted @ 2022-02-10 20:27 悟透 阅读(181) 评论(0) 推荐(0) 编辑
摘要:Python源码: def wx_path(): ## 获取当前用户名 users = os.path.expandvars('$HOMEPATH') ## 找到3ebffe94.ini配置文件 f = open(r'C:' + users + '\\AppData\\Roaming\\Tencen 阅读全文
posted @ 2022-02-06 11:47 悟透 阅读(650) 评论(0) 推荐(0) 编辑
摘要:r:表示不转义字符,比如遇到"\n" "\t" 原样输出,是不是输出回车和Tab制表符 f:表示识别字符串里的变量或“\n”这写特殊字符。 阅读全文
posted @ 2022-02-02 17:30 悟透 阅读(1307) 评论(0) 推荐(0) 编辑
摘要:▍1、字母异位词 两个单词如果包含相同的字母,次序不同,则称为字母易位词(anagram)。 例如,“silent”和“listen”是字母易位词,而“apple”和“aplee”不是易位词。 from collections import Counter s1 = 'below' s2 = 'el 阅读全文
posted @ 2022-01-30 20:29 悟透 阅读(537) 评论(0) 推荐(0) 编辑
摘要:- 1.在开始和结束日期设置范围,这里是从大月到小月生成; 2.可以将下面"月减一和天减一",减法修改成加法 ”月加一和天加一“ 来实现小月到大月。 3.代码里将结果保存到列表中,你可以根据实际情况放到其他类型变量里。 ## 开始、结束日期 date_start = '1202' date_end 阅读全文
posted @ 2022-01-29 21:39 悟透 阅读(811) 评论(0) 推荐(0) 编辑
摘要:题目: 题目: 小军、小刚、小丽三个人的年龄是27岁; 小军、小刚的年龄和是19岁; 小军、小丽两人的年龄和是17岁。 问: 小军()岁,小刚()岁,小丽()岁 提示 此题用“减法”。 源码: #!/usr/bin/env python3 #_*_ encoding:UTF-8 _*_ print( 阅读全文
posted @ 2022-01-27 18:04 悟透 阅读(1163) 评论(0) 推荐(0) 编辑
摘要:题目: 有4个小朋友,2人一组,他们能分几组? 源码: #!/usr/bin/env python3 #_*_ encoding:UTF-8 _*_ from itertools import combinations import sys print("\n"+" 小学数学 (二年级) ".cen 阅读全文
posted @ 2022-01-27 18:01 悟透 阅读(322) 评论(0) 推荐(0) 编辑
摘要:代码: >>> from urllib import request >>> urllib.request.urlretrieve('https://pan.baidu.com/download',r'D:\1.html') from urllib import request 也可以用 impor 阅读全文
posted @ 2022-01-17 20:38 悟透 阅读(76) 评论(0) 推荐(0) 编辑
摘要:执行命令: > python -m pip install --upgrade pip 但是提示失败。 一种原因是windows没有安装编译环境和Python sip 1.安装windows编译环境: 安装文件下载地址:https://www.cnblogs.com/wutou/p/15796990 阅读全文
posted @ 2022-01-13 12:38 悟透 阅读(157) 评论(0) 推荐(0) 编辑
摘要:错误提示 error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https:// visualstudio.microsoft.com/visual-cpp- 阅读全文
posted @ 2022-01-13 11:50 悟透 阅读(1048) 评论(0) 推荐(0) 编辑
摘要:脚本功能:批量替换excel文件里字符串内容,并保留原有样式。 运行环境:Linux Python 注意:1.只支持xls(excel 97、2003) 但不支持xlsx(excel 2010+) 2.脚本中的注释,在实际使用时可以删除,在某些环境下可能会有奇怪问题。 #!/usr/bin/pyth 阅读全文
posted @ 2022-01-10 21:09 悟透 阅读(821) 评论(0) 推荐(0) 编辑

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