随笔分类 - python
摘要:不使用logging模块,只是简单的输出某一个函数的异常信息 # coding:utf-8 import sys import pandas as pd def test(): try: pd.DataFrame('') except ValueError: error_msg = '执行异常![{
阅读全文
摘要:参数说明 -F, –onefile | 打包一个单个文件,如果你的代码都写在一个.py文件的话,可以用这个,如果是多个.py文件就别用 -D, –onedir | 打包多个文件,在dist中生成很多依赖文件,适合以框架形式编写工具代码 -w, –windowed,–noconsole | 使用Win
阅读全文
摘要:```python import os from datetime import datetime import pytz from exchangelib import Credentials, Account, Configuration, DELEGATE, Q, FileAttachment
阅读全文
摘要:import datetime import calendar def get_quarter_date(quarter='current'): """ 获取当前季度或上一季度的起止日期 :param quarter: [current , last], default current :retur
阅读全文
摘要:单元格拆分 def get_index(capital): """ 大写字母(Excel列头)转数字 :param capital: 'A' --> 0, 'AA' --> 26 :return: int """ number = 0 capital = capital.upper() for ch
阅读全文
摘要:### 纵向拼接 ```python from PIL import Image def image_splicing(pic01, pic02): """ 图片拼接 :param pic01: 图片1路径 :param pic02: 图片2路径 :return: 保存路径 """ with Ima
阅读全文
摘要:def seconds_to_str(seconds): """ 时间戳转为 天 时 分 秒 :param seconds: int or float :return: str eg: 360 --> 6分0秒 """ days = int(seconds // (3600 * 24)) hours
阅读全文
摘要:获取上月开始结束日期 方法一 import datetime def get_date_of_last_month(form="%Y-%m-%d"): """ 获取上月开始结束日期 :param form 返回值显示格式 :return: str,date tuple """ today = dat
阅读全文
摘要:只使用`reportlab`库好像没法在已经有内容的PDF页面中写入数据,只能生成一个空的PDF文件再写入。所以配合`pdfrw`库来实现的。具体见示例 ```python from reportlab.pdfgen.canvas import Canvas from pdfrw import Pd
阅读全文
摘要:###字母转数字 def get_index(capital): """ 大写字母(Excel列头)转索引 :param capital: 'A' --> 0, 'AA' --> 26 :return: int """ number = 0 capital = capital.upper() for
阅读全文
摘要:###使用openpyxl实现 只支持xlsx文件,不支持xls import openpyxl def read_cell(io, sheet, cell='A2'): """ 读取单元格 :param io: Excel文件路径 :param sheet: 读取哪一张表,str, int eg:
阅读全文
摘要:import datetime def get_date_of_last_week(form='%Y-%m-%d'): """ 获取上周开始结束日期 :param form: 日期格式 :return: str,date tuple """ today = datetime.date.today()
阅读全文
摘要:注:chinese_calander库需要每年手动更新一次 import datetime import chinese_calendar def get_holidays(year=None, include_weekends=True): """ 获取某一年的所有节假日,默认当年 :param
阅读全文
摘要:通过发票左上角的二维码信息,获取发票的关键信息,只需将图片格式的电子发票或扫描后的发票图片传入即可. 测试结果如下: * 增值税电子普通发票:`{'发票代码': '031xxxxxx311', '发票号码': '74xxxx17', '不含税金额': '13665.98', '开票日期': '202
阅读全文
摘要:下面示例代码,是将横向纸张旋转为纵向(根据纸张大小判断纸张方向) 方法一:使用`PyPDF2`库 ```python from PyPDF2 import PdfFileWriter, PdfFileReader def page_rotation(old_file, new_file): """
阅读全文
摘要:实现WPS文件转PDF,需要安装金山WPS ```python import os from win32com.client import Dispatch def wps_et_to_pdf(file, pdf_file=None): """ wps/et 转 PDF :param file: w
阅读全文
摘要:import os from PIL import Image from reportlab.pdfgen import canvas def image_resize(img, *args, multiple=None): """ 图片缩放 如果按倍数缩放图片,则不用传args, 否则要传入需要缩
阅读全文
摘要:**说明** 为了方便将pdf格式发票转为图片,找到以下方法,转换后的效果非常不错,特此记录在自己的笔记中,根据自己的需要,代码稍微有所优化修改 >*参考网址:https://zhuanlan.zhihu.com/p/102742847* **三方库安装** ```python pip instal
阅读全文
摘要:要实现中英文切换,首先Windows系统必须要有中文语言和英文语言,才能实现输入法(语言)切换。 import win32api import win32gui from win32con import WM_INPUTLANGCHANGEREQUEST def change_language(la
阅读全文
摘要:实际上ofd、docx、xlsx等文件就是一个压缩文件,是可以被解压处理的。所以我们把一个ofd格式的发票文件解压后就可以看到它的目录,如下: ![](https://img2020.cnblogs.com/blog/1425658/202101/1425658-20210125134534946-
阅读全文