python

安装第三方库

在 文件名.bat 中, 输入

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple Pillow
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pygame
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple sprites
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple baidu-aip
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple chardet
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple PyAudio

pause

卸载所有第三方库

pip freeze>modules.txt
pip uninstall -r modules.txt -y

VsCode python输出乱码(中文)

import io
import sys

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

强制刷新标准输出缓冲区

import sys

sys.stdout.flush() 

打包

安装pyinstaller

pip3 install pyinstaller

打包文件

pyinstaller -D 打包的文件名

日期转换为时间戳

import datetime
import time

date_obj = datetime.datetime.strptime(str(day), '%Y-%m-%d') # 转换为datetime对象
timestamp  = time.mktime(date_obj.timetuple()) # 转换为时间戳
print(timestamp)

html转义字符转换成相应的符号

import html

# 将HTML转义字符转换成相应的符号
def decode_html_symbols(s):
    s = s.replace(">", ">").replace(">", ">") # 将">"和">"转换成">"
    s = s.replace("&lt;", "<").replace("&#60;", "<") # 将"&lt;"和"&#60;"转换成"<"
    s = s.replace("&nbsp;", " ") # 将"&nbsp;"转换成空格
    s = s.replace("&hellip;", "…") # 将"&hellip;"转换成省略号
    s = s.replace("&ldquo;", "“").replace("&rdquo;", "”") # 将"&ldquo;"和"&rdquo;"转换成左右双引号    
    s = s.replace("&lsquo;", "‘").replace("&rsquo;", "’") # 将"&lsquo;"和"&rsquo;"转换成左右单引号
    s = s.replace("&mdash;", "—") # 将"&mdash;"转换成破折号
    s = s.replace("&ndash;", "–") # 将"&ndash;"转换成短横线
    s = s.replace("&quot;", '"') # 将"&quot;"转换成双引号
    s = s.replace("&amp;", '&').replace("&#38;", '&') # 将"&amp;"和"&#38;"转换成和号
    s = s.replace("&apos;", "'").replace("&#039;", "'") # 将"&apos;"和"&#039;"转换成单引号
    s = s.replace("&euro;", "€") # 将"&euro;"转换成欧元符号
    s = s.replace("&pound;", "£") # 将"&pound;"转换成英镑符号
    s = s.replace("&yen;", "¥") # 将"&yen;"转换成人名币符号
    s = s.replace("&sect;", "§") # 将"&sect;"转换成双S号或分段符号
    s = s.replace("&para;", "¶") # 将"&para;"转换成段落符号
    # s = html.unescape(s) # 将其他HTML转义字符进行转换
    return s

cvs写入,遇到编码问题

with open(文件名,'w', newline='', encoding='utf-8') as f:
	writer = csv.writer(f)
	writer.writerows(内容)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

谢谢 啊sir

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值