lanceadd |
| 问与答 • lanceadd python3 多个多层 dict 合并 2020 年 12 月 7 日 • 最后回复来自 lanceadd | 5 |
| Python • lanceadd Reportlab 如何向已经存在 pdf 中的指定位置插入一个饼状图 2020 年 11 月 13 日 • 最后回复来自 renmu123 | 2 |
| JavaScript • lanceadd Nest.js 和 Egg.js 选哪个 2020 年 7 月 2 日 • 最后回复来自 fengyunselang | 7 |
| Vim • lanceadd 如何解决 Mac 下 vim 中无法使用 commad+c/v 来复制粘贴 2020 年 3 月 2 日 • 最后回复来自 hfpp2012 | 17 |
| Vim • lanceadd 如何让 Macvim 和 vim 分别使用不同的配置文件 2020 年 3 月 1 日 • 最后回复来自 lanceadd | 6 |
| 问与答 • lanceadd 优化家庭 wifi 信号覆盖 2019 年 12 月 17 日 • 最后回复来自 lanceadd | 5 |
| 问与答 • lanceadd 如何实现 shell 自动填写 ssh 登录密码,用管道和重定向 2019 年 8 月 22 日 • 最后回复来自 lanceadd | 7 |
| 问与答 • lanceadd Mac os 的证书本地劫持如何解决 2019 年 8 月 6 日 • 最后回复来自 wonderingray | 3 |
lanceadd 最近回复了
| 回复了 zhouxiaoxiao 创建的主题 › 如果你的组员,用 controller 直接调用 mapper,是不是可以直接 fire 了2025 年 6 月 27 日 |
emmm 你们还是手搓的 controller 吗,直接写个代码生成器,设计完接口生成一下,controller ,service ,serviceMockImpl 啥的都生成好,然后同事只需要实现那个 service ,xxxServiceImpl 里他想怎么弄都行,最后加个注解 @Primary 把原来 MockImpl 挤下去完事了,避免没必要的手搓就没这些问题
| 回复了 loveyou1 创建的主题 › 大家五一都准备去哪里2025 年 4 月 28 日 |
@LetsGiao 怀旧服吗
| 回复了 puppyxxx 创建的主题 › 最近要做一个 AI 应用落地,一些困惑希望有人可以指导2025 年 3 月 6 日 |
@highkay 刚好最近想做这个,star+1 参考下老哥的项目
| 回复了 seventhbible 创建的主题 › 请问在将自己的 Python 工程输出 EXE 文件时,如何将 xml 等文件一起打包进去。2021 年 2 月 19 日 |
| 回复了 lanceadd 创建的主题 › python3 多个多层 dict 合并2020 年 12 月 8 日 |
解决了
```
def recursive_update(
default: dict,
custom: dict
):
"""
递归更新 dict
:param default:
:param custom:
:return:
"""
if not isinstance(default, dict) or not isinstance(custom, dict):
raise TypeError('Params of recursive_update should be dicts')
for key in custom:
if isinstance(custom[key], dict) and isinstance(default.get(key), dict):
default[key] = recursive_update(default[key], custom[key])
else:
default[key] = custom[key]
return default
```
```
def recursive_update(
default: dict,
custom: dict
):
"""
递归更新 dict
:param default:
:param custom:
:return:
"""
if not isinstance(default, dict) or not isinstance(custom, dict):
raise TypeError('Params of recursive_update should be dicts')
for key in custom:
if isinstance(custom[key], dict) and isinstance(default.get(key), dict):
default[key] = recursive_update(default[key], custom[key])
else:
default[key] = custom[key]
return default
```
| 回复了 lanceadd 创建的主题 › python3 多个多层 dict 合并2020 年 12 月 7 日 |
多个嵌套字典合并为一个
| 回复了 lanceadd 创建的主题 › python3 多个多层 dict 合并2020 年 12 月 7 日 |
@renmu123 @westoy 抱歉抱歉我也不知道为啥会缺了一块, 发布前预览是没问题的, 另外一个 dict 也是这个,但是 user_id,title_id 这些 key 可能不相同,然后可能层级也不一样,可能会只有两层那种,然后想把一个 dict,update 到另外一个 dict 上,如果那一层的 key 相同 value 不同就合并上去,举个例子按照我上面那个结构,user_id 、title_id 相同但是 relation_id 不同,怎么把它俩合并起来,我原本以为 dict.update()就好了,但是发现对多层的 dict 直接 update 会直接覆盖,然后发现只能一层一层的 update,就很尴尬,除了递归还有啥办法可以更新不同深度的嵌套字典的值吗
| 回复了 lanceadd 创建的主题 › Reportlab 如何向已经存在 pdf 中的指定位置插入一个饼状图2020 年 11 月 13 日 |
我会了
```
import io
from PyPDF2 import PdfFileReader, PdfFileWriter
from reportlab.graphics import renderPDF
from reportlab.graphics.charts.piecharts import Pie
from reportlab.graphics.shapes import Drawing
from reportlab.lib.pagesizes import A4
from reportlab.pdfgen import canvas
packet = io.BytesIO()
can = canvas.Canvas(packet, pagesize=A4)
pie = Pie()
pie.data = [20, 10, 5, 5, 5]
pie.labels = ['a', 'b', 'c', 'd', 'e']
pie.sideLabels = True
d = Drawing(100, 100)
d.add(pie)
renderPDF.draw(d, can, 20, 20)
can.save()
packet.seek(0)
new_pdf = PdfFileReader(packet)
existing_pdf = PdfFileReader(open('example_06.pdf', 'rb'))
output = PdfFileWriter()
page = existing_pdf.getPage(0)
page.mergePage(new_pdf.getPage(0))
output.addPage(page)
outputStream = open('result.pdf', 'wb')
output.write(outputStream)
outputStream.close()
```
```
import io
from PyPDF2 import PdfFileReader, PdfFileWriter
from reportlab.graphics import renderPDF
from reportlab.graphics.charts.piecharts import Pie
from reportlab.graphics.shapes import Drawing
from reportlab.lib.pagesizes import A4
from reportlab.pdfgen import canvas
packet = io.BytesIO()
can = canvas.Canvas(packet, pagesize=A4)
pie = Pie()
pie.data = [20, 10, 5, 5, 5]
pie.labels = ['a', 'b', 'c', 'd', 'e']
pie.sideLabels = True
d = Drawing(100, 100)
d.add(pie)
renderPDF.draw(d, can, 20, 20)
can.save()
packet.seek(0)
new_pdf = PdfFileReader(packet)
existing_pdf = PdfFileReader(open('example_06.pdf', 'rb'))
output = PdfFileWriter()
page = existing_pdf.getPage(0)
page.mergePage(new_pdf.getPage(0))
output.addPage(page)
outputStream = open('result.pdf', 'wb')
output.write(outputStream)
outputStream.close()
```