python实现2,5,8到101?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python实现2,5,8到101?相关的知识,希望对你有一定的参考价值。

参考技术A 你想要的是一个从2开始,以3为步长,到101结束的数列吗?如果是的话,可以使用Python的range函数来生成这个数列,代码如下:
numbers = list(range(2, 102, 3))
print(numbers)

python实现通用json导入到mysql

import json
from Db import Db

db = Db()

‘‘‘
参考配置文件
{
    "file": "test.json",    
    "path": "data",
    "table": "tk_bill",
    "comitcount": 50,
    "map": {
        "trade_id": "trade_id",
        "tk_status": "tk_status",
        "item_title": "item_title",
        "alipay_total_price": "alipay_total_price",
        "tk_paid_time": "tk_paid_time",
        "pub_share_pre_fee": "pub_share_pre_fee",
        "subsidy_fee": "subsidy_fee",
        "tk_settletime": "tk_settletime"
    }
}
‘‘‘


def loadJsonFromFile(file):
    ‘‘‘
    加载配置
    :return:
    ‘‘‘
    with open(file) as f:
        return json.load(f)


def getData(jsonObj, path):
    return jsonObj[path]


if __name__ == __main__:
    importConfig = loadJsonFromFile("jsonmap.conf")
    # 获取要导入的表名
    tableName = importConfig["table"]
    comitcount = importConfig["comitcount"]
    cols = []
    colsidx = []
    for k, v in importConfig["map"].items():
        cols.append(k)
        colsidx.append(v)
    sqlpre = "insert into %s(%s) values " % (tableName, ",".join(cols))
    jsonobj = loadJsonFromFile(importConfig["file"])
    # 获取列表部分
    pathArr = []
    if importConfig["path"] != "":
        pathArr = importConfig["path"].split(".")
        for key in pathArr:
            jsonobj = getData(jsonobj, key)
    vlist = []
    for i, data in enumerate(jsonobj):
        print("处理第%d行" % (i + 1))
        temlist = [];
        for k in colsidx:
            s = "‘%s‘" % data[k].replace("", "‘‘")
            temlist.append(s)
        vlist.append("(%s)" % ",".join(temlist))
        if i % comitcount == 0:
            sql = sqlpre + ",".join(vlist)
            db.execSql(sql)
            vlist.clear()
            continue
    if len(vlist) > 0:
        sql = sqlpre + ",".join(vlist)
        db.execSql(sql)
        vlist.clear()
    print("处理完成")

 

以上是关于python实现2,5,8到101?的主要内容,如果未能解决你的问题,请参考以下文章

华为机试真题 Python 实现不含 101 的数2022.11 Q4新题

Python 切片

第8课 python 项目实操(常用2个模块)

python切片

Python ❀ 函数

Python编程入门到实践 - 笔记( 8 章)