对在xml写sql语句快速生成占位符

如果要insert一堆字段

number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status,
                           amount, remark, phone, address, user_name, consignee, cancel_reason, rejection_reason,
                           cancel_time, estimated_delivery_time, delivery_status, delivery_time, pack_amount,
                           tableware_number, tableware_status

要一个个的#{nuber}十分繁琐

所以借此写一个python的脚本处理字符串

import pyperclip as pc

input_text = ''
while True:
    line = input()
    if not line:
        break  # 当输入为空行时结束输入
    input_text += line + '\n'
a = input_text.replace("\n", "").replace(" ", "").split(",")
print(a)
b = ""
for i, j in enumerate(a):
    if j.strip():  # 检查字段名称是否非空
        while True:
            try:
                idx = j.index("_")
                j = j.replace(j[idx] + j[idx + 1], j[idx + 1].upper())
            except ValueError:
                break
        b += "#{" + j + "}"
        if i != len(a) - 1:  # 避免在最后一个字段后添加逗号
            b += ","
print(b)
pc.copy(b)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值