分类目录归档:语言

解决 idea 无法创建java8 模版


解决 idea 无法创建java8 模版

由于 Spring 官方不再维护 旧的版本了导致的 https://start.spring.io

解决方式很简单 切换到 阿里源就可以了 https://start.aliyun.com/

项目生成 成功

总结 :IDEA 内置的 Spring Initializr 创建 Spring Boot 项目实际上是依赖官方链接功能,官方不维护后旧版本功能无法使用。通过更改源可以解决。

Read more

SQLAlchemy 快速使用


SQLAlchemy

ORM 工具库

https://docs.sqlalchemy.org/en/20/index.html

ORM 快速入门

声明模型

Declare Models

我们定义模块级构造,这些构造将形成我们将从数据库查询的结构。

这种结构被称为声明式映射(Declarative Mapping),它同时定义了Python对象模型,以及描述特定数据库中存在或将存在的真实SQL表的数据库元数据:

from typing import Optional, List
from sqlalchemy import ForeignKey, String
from sqlalchemy.o

Read more

pypi上传包


1 账号注册

https://test.pypi.org/ # 测试环境

https://pypi.org/ 正式环境

可以先在测试环境测试上传再上传到正式环境

2 固定的目录结构

上穿到pypi 的包的目录结构是固定

example_package
----LICENSE.txt    #版权声明文件
----README.md      #分发包的详细介绍文件
----example_pkg    # 你要上传的代码包
    ----__init__.py
    .......
----setup.py       #为打包做准备的设置文件 ,这个是最关键的
----tests    

Read more

使用openpyxl 操作excel(xlsx)


使用openpyxl 操作excel(xlsx)

由于 xlrd 和xlwt 停止更新并阉割了自己的能力来推荐使用这个库,涉及到xlsx文件的处理使用这个库。

这个库不支持xls操作

安装

pip install openpyxl 

# 如果涉及图片处理
pip install pillow

功能介绍

openpyxl 可以对xlsx文件进行读取和写入操作,字体单元格对齐格式等样式操作

读写操作

介绍

openpyxl 通过 Workbook sheet cell 对象分别控制 表格文件 sheet 页 和单元格所以我们可以同时读取和写入

demo 写入&读取

#!/usr/bi

Read more

openpyxl 使用


openpyxl 使用

由于 xlrd 和xlwt 不在更新并阉割了自己的能力来推荐使用这个库,那就使用这个库吧。

安装

pip install openpyxl 

# 如果涉及图片处理
pip install pillow

写入

from openpyxl import Workbook # Workbook excel 对象
from openpyxl.utils import get_column_letter

 wb = Workbook()
 ws = wb.active # 激活工作区 == 返回一个默认sheet页
# 其他创建sheet 页方法
ws1 = wb.cr

Read more

reportlab 写入PDF


import re from reportlab import platypus from reportlab.lib.pagesizes import letter, A4 from reportlab.lib.units import inch from reportlab.platypus import SimpleDocTemplate, Image from reportlab.pdfgen import canvas from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.cidfonts import Uni

Read more

python 性能提升小技巧--去掉所有print


python 性能提升小技巧--去掉所有print

python 中的 print会 使用操作系统输出流打印效率会慢一些,应该用logging 模块输出到日志文件中

一个简答例子说明两者效率差异:

#!/usr/bin/env python
#-*- coding: utf-8 -*-
#E_MAIL: renoyuan@foxmail.com
#AUTHOR: reno 

import time
import logging

logging.basicConfig(level=logging.INFO,
                      format='%(asctim

Read more

python 内存中读写文件流


python 内存中读写文件流

作用:避免磁盘io,性能上去了

demo 图片旋转

from typing import Union
from PIL import Image
from io import BytesIO

# BytesIO 可以开辟一段内存空间用来对Bytes类型进行IO操作
def img_rotate(f_b: bytes, angle:Union[int,float], endstuff="PNG") ->bytes:

  """

  图片旋转

  """

  f=Byte

Read more

python excel 处理 xlrd & xlwt &xlutils


python excel 处理

方案一 xlrd & xlwt &xlutils

使用xlrd 用来读取 xls 文件

xlrd --> xls read

安装

pip install xlrd

使用

import xlrd

book = xlrd.open_workbook("myfile.xls") # 创建读取xls 对象

print("表格文件的sheet页有  {0}".format(book.nsheets))
print("表格文件的sheet页名: {0}".format(book.she

Read more

服务器重启后 Nvidia 环境错误


服务器重启后 Nvidia 环境错误

服务器重启后 服务运行报错,查看日志是Nvidia 驱动出了问题

image-20220110110219727

system has unsupported display driver / cuda driver combination.
系统具有不受支持的显示驱动程序/cuda驱动程序组合。

查看一下

image-20220110110814343

看来是驱动版本匹配出了问题

重装

sudo /usr/bin/nvidia-uninstall
提示自动重装 选择yes

Read more