C/C++自定义读取ini、cfg配置文件

常见cfg、ini文件如下:

[config1]
setting=192.168.1.1
[config2]
setting=192.168.1.2
[config3]
setting=192.168.1.3

示例代码使用

// opt_ini.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//#include <iostream>
#include "cfg.h"int main()
{cfg_load("config.cfg");cfg_print();cfg_set("config1","setting","192.168.101.78");cfg_save("config2.cfg");cfg_print();cfg_release();
}// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件

 示例代码运行结果:

 

附主要代码: 

static int cfg_parse_stream(CFG_reader reader, void* stream, CFG_handler handler,void* user)
{char line[CFG_MAX_LINE];size_t max_line = CFG_MAX_LINE;char section[MAX_SECTION] = "";char prev_name[MAX_NAME] = "";char* start;char* end;char* name;char* value;int lineno = 0;int error = 0;#define HANDLER(u, s, n, v) handler(u, s, n, v)while (reader(line, (int)max_line, stream) != NULL) {lineno++;start = line;if (lineno == 1 && (unsigned char)start[0] == 0xEF &&(unsigned char)start[1] == 0xBB &&(unsigned char)start[2] == 0xBF) {start += 3;}start = lskip(rstrip(start));if (strchr(CFG_START_COMMENT_PREFIXES, *start)) {/* Start-of-line comment */}else if (*prev_name && *start && start > line) {end = find_chars_or_comment(start, NULL);if (*end)*end = '\0';rstrip(start);if (!HANDLER(user, section, prev_name, start) && !error)error = lineno;}else if (*start == '[') {/* A "[section]" line */end = find_chars_or_comment(start + 1, "]");if (*end == ']') {*end = '\0';strncpy0(section, start + 1, sizeof(section));*prev_name = '\0';}else if (!error) {/* No ']' found on section line */error = lineno;}}else if (*start) {/* Not a comment, must be a name[=:]value pair */end = find_chars_or_comment(start, "=:");if (*end == '=' || *end == ':') {*end = '\0';name = rstrip(start);value = end + 1;end = find_chars_or_comment(value, NULL);if (*end)*end = '\0';value = lskip(value);rstrip(value);/* Valid name[=:]value pair found, call handler */strncpy0(prev_name, name, sizeof(prev_name));if (!HANDLER(user, section, name, value) && !error)error = lineno;}else if (!error) {error = lineno;}}}return error;
}static int cfg_parse_file(FILE* file, CFG_handler handler, void* user)
{return cfg_parse_stream((CFG_reader)fgets, file, handler, user);
}static int cfg_parse(const char* filename, CFG_handler handler, void* user)
{FILE* file;int error;file = fopen(filename, "r");if (!file) {cfg_error("%s:%03d open %s error!\n", __FUNCTION__, __LINE__, filename);return -1;}error = cfg_parse_file(file, handler, user);fclose(file);return error;
}
int User;
static char Prev_section[50];static unsigned int TrailerDateOfProduction(char* s)
{unsigned int ret;int i;ret = 0;if (!s){return 0;}while (*s != '\0') {if (*s=='-')s++;if (*s >= '0' && *s <= '9')i = *s - '0';else if (*s >= 'a' && *s <= 'f')i = *s - 'a' + 0xa;else if (*s >= 'A' && *s <= 'F')i = *s - 'A' + 0xa;elsereturn 0;ret = (ret << 4) + i;s++;}return ret;
}/*** \description cfg init.* * \author sunsz* \date   2023/09/23 * */
static int GetConfig(void* user, const char* section, const char* name, const char* value){size_t len = 0;unsigned int cfg_num = 0;unsigned int cfg_data_num = 0;User = *((int*)user);if (!section) {return 1;}if (!name) {return 1;}if (!value) {cfg_error("%s:%03d [%s]%s = null\n", __FUNCTION__, __LINE__, section, name);return 1;}if (section && (!_stricmp(section, Prev_section))) {len = strlen(section);cfg_num = _cfg_config.cfg_section_num - 1;cfg_data_num = _cfg_config.cfg_section[cfg_num].cfg_data_num;_cfg_config.cfg_section[cfg_num].cfg_section_name = malloc(len + 1);if (_cfg_config.cfg_section[cfg_num].cfg_section_name != NULL) {memset(_cfg_config.cfg_section[cfg_num].cfg_section_name, 0, len + 1);strcpy(_cfg_config.cfg_section[cfg_num].cfg_section_name, section);}   len = strlen(name);_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_name = malloc(len + 1);if (_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_name != NULL) {memset(_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_name, 0, len + 1);strcpy(_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_name, name);}len = strlen(value);_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_value = malloc(len + 1);if (_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_value != NULL) {memset(_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_value, 0, len + 1);strcpy(_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_value, value);}_cfg_config.cfg_section[cfg_num].cfg_data_num++;strcpy(Prev_section, section);return 0;}else if (section) {cfg_num = _cfg_config.cfg_section_num;cfg_data_num = _cfg_config.cfg_section[cfg_num].cfg_data_num;len = strlen(section);_cfg_config.cfg_section[cfg_num].cfg_section_name = malloc(len + 1);if (_cfg_config.cfg_section[cfg_num].cfg_section_name != NULL) {memset(_cfg_config.cfg_section[cfg_num].cfg_section_name, 0, len + 1);strcpy(_cfg_config.cfg_section[cfg_num].cfg_section_name, section);}len = strlen(name);_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_name = malloc(len + 1);if (_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_name != NULL) {memset(_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_name, 0, len + 1);strcpy(_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_name, name);}len = strlen(value);_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_value = malloc(len + 1);if (_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_value != NULL) {memset(_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_value, 0, len + 1);strcpy(_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_value, value);}_cfg_config.cfg_section[cfg_num].cfg_data_num++;_cfg_config.cfg_section_num++;strcpy(Prev_section, section);return 0;}return 0;
}
/*** \description set cfg value.* * \author sunsz* \date   2023/09/23 * */
int cfg_set(const char*section, const char*name, const char*value) {int len = 0;int _sectionin = 0;unsigned int cfg_num = 0;unsigned int cfg_data_num = 0;cfg_debug("%s:%03d\n", __FUNCTION__, __LINE__);if (section == NULL || name == NULL || value == NULL) {cfg_error("%s:%03d parameter null!\n", __FUNCTION__, __LINE__);return 1;}for (size_t i = 0; i < _cfg_config.cfg_section_num; i++) {if (!_stricmp(_cfg_config.cfg_section[i].cfg_section_name, section)) {_sectionin = 1;for (size_t j = 0; j < _cfg_config.cfg_section[i].cfg_data_num; j++) {if (_cfg_config.cfg_section[i].cfg_data[j].cfg_name) {if (!_stricmp(_cfg_config.cfg_section[i].cfg_data[j].cfg_name, name)) {if (_cfg_config.cfg_section[i].cfg_data[j].cfg_value != NULL) {len = strlen(_cfg_config.cfg_section[i].cfg_data[j].cfg_value);memset(_cfg_config.cfg_section[i].cfg_data[j].cfg_value, 0, len);free(_cfg_config.cfg_section[i].cfg_data[j].cfg_value);_cfg_config.cfg_section[i].cfg_data[j].cfg_value = NULL;if (value[0]) {len = strlen(value);_cfg_config.cfg_section[i].cfg_data[j].cfg_value = malloc(len + 1);if (_cfg_config.cfg_section[i].cfg_data[j].cfg_value != NULL) {memset(_cfg_config.cfg_section[i].cfg_data[j].cfg_value, 0, len + 1);strcpy(_cfg_config.cfg_section[i].cfg_data[j].cfg_value, value);}}else {len = 1;_cfg_config.cfg_section[i].cfg_data[j].cfg_value = malloc(len + 1);if (_cfg_config.cfg_section[i].cfg_data[j].cfg_value != NULL) {memset(_cfg_config.cfg_section[i].cfg_data[j].cfg_value, 0, len + 1);strcpy(_cfg_config.cfg_section[i].cfg_data[j].cfg_value, "");}}}else {if (value[0]) {len = strlen(value);_cfg_config.cfg_section[i].cfg_data[j].cfg_value = malloc(len + 1);if (_cfg_config.cfg_section[i].cfg_data[j].cfg_value != NULL) {memset(_cfg_config.cfg_section[i].cfg_data[j].cfg_value, 0, len + 1);strcpy(_cfg_config.cfg_section[i].cfg_data[j].cfg_value, value);}}else {len = 1;_cfg_config.cfg_section[i].cfg_data[j].cfg_value = malloc(len + 1);if (_cfg_config.cfg_section[i].cfg_data[j].cfg_value != NULL) {memset(_cfg_config.cfg_section[i].cfg_data[j].cfg_value, 0, len + 1);strcpy(_cfg_config.cfg_section[i].cfg_data[j].cfg_value, "");}}}return 0;}}}//没有找到nameif (name[0] && value[0]) {len = strlen(name);cfg_data_num = _cfg_config.cfg_section[i].cfg_data_num;_cfg_config.cfg_section[i].cfg_data[cfg_data_num].cfg_name = malloc(len + 1);if (_cfg_config.cfg_section[i].cfg_data[cfg_data_num].cfg_name != NULL) {memset(_cfg_config.cfg_section[i].cfg_data[cfg_data_num].cfg_name, 0, len + 1);strcpy(_cfg_config.cfg_section[i].cfg_data[cfg_data_num].cfg_name, name);}len = strlen(value);_cfg_config.cfg_section[i].cfg_data[cfg_data_num].cfg_value = malloc(len + 1);if (_cfg_config.cfg_section[i].cfg_data[cfg_data_num].cfg_value != NULL) {memset(_cfg_config.cfg_section[i].cfg_data[cfg_data_num].cfg_value, 0, len + 1);strcpy(_cfg_config.cfg_section[i].cfg_data[cfg_data_num].cfg_value, value);}_cfg_config.cfg_section[i].cfg_data_num++;return 0;}} }if (!_sectionin) {//没有找到sectionif (name[0] && value[0]) {len = strlen(section);cfg_num = _cfg_config.cfg_section_num;cfg_data_num = _cfg_config.cfg_section[cfg_num].cfg_data_num;_cfg_config.cfg_section[cfg_num].cfg_section_name = malloc(len + 1);if (_cfg_config.cfg_section[cfg_num].cfg_section_name != NULL) {memset(_cfg_config.cfg_section[cfg_num].cfg_section_name, 0, len + 1);strcpy(_cfg_config.cfg_section[cfg_num].cfg_section_name, section);}len = strlen(name);_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_name = malloc(len + 1);if (_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_name != NULL) {memset(_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_name, 0, len + 1);strcpy(_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_name, name);}len = strlen(value);_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_value = malloc(len + 1);if (_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_value != NULL) {memset(_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_value, 0, len + 1);strcpy(_cfg_config.cfg_section[cfg_num].cfg_data[cfg_data_num].cfg_value, value);}_cfg_config.cfg_section[cfg_num].cfg_data_num++;_cfg_config.cfg_section_num++;return 0;}}return 1;
}
/*** \description get value by section and name.* * \author sunsz* \date   2023/09/23 * */
char* cfg_get(const char* section, const char* name) {int len = 0;int _sectionin = 0;unsigned int cfg_num = 0;unsigned int cfg_data_num = 0;cfg_debug("%s:%03d\n", __FUNCTION__, __LINE__);if (section == NULL || name == NULL) {cfg_error("%s:%03d parameter null!\n", __FUNCTION__, __LINE__);return NULL;}for (size_t i = 0; i < _cfg_config.cfg_section_num; i++) {if (!_stricmp(_cfg_config.cfg_section[i].cfg_section_name, section)) {_sectionin = 1;for (size_t j = 0; j < _cfg_config.cfg_section[i].cfg_data_num; j++) {if (_cfg_config.cfg_section[i].cfg_data[j].cfg_name) {if (!_stricmp(_cfg_config.cfg_section[i].cfg_data[j].cfg_name, name))return _cfg_config.cfg_section[i].cfg_data[j].cfg_value;}}}}return NULL;
}
/*** \description write cfg data to log.* * \author sunsz* \date   2023/09/23 * */
void cfg_print() {cfg_debug("%s:%03d\n", __FUNCTION__, __LINE__);cfg_info("\n");for (size_t i = 0; i < _cfg_config.cfg_section_num; i++) {cfg_info("[%s]\n", _cfg_config.cfg_section[i].cfg_section_name);for (size_t j = 0; j < _cfg_config.cfg_section[i].cfg_data_num; j++) {cfg_info("%s=%s\n", _cfg_config.cfg_section[i].cfg_data[j].cfg_name, _cfg_config.cfg_section[i].cfg_data[j].cfg_value);}}
}
/*** \description write cfg data.* * \author sunsz* \date   2023/09/23 * */
int cfg_save(const char* cfg_name) {FILE* file;char buffer[1024] = { 0x00 };cfg_debug("%s:%03d\n", __FUNCTION__, __LINE__);file = fopen(cfg_name, "w");if (!file) {cfg_error("%s:%03d open %s error!\n",__FUNCTION__,__LINE__, cfg_name);return 1;}for (size_t i = 0; i < _cfg_config.cfg_section_num; i++) {memset(buffer, 0, 1024);sprintf(buffer, "[%s]\n", _cfg_config.cfg_section[i].cfg_section_name);fwrite(buffer,1,strlen(buffer), file);for (size_t j = 0; j < _cfg_config.cfg_section[i].cfg_data_num; j++) {sprintf(buffer, "%s=%s\n", _cfg_config.cfg_section[i].cfg_data[j].cfg_name, _cfg_config.cfg_section[i].cfg_data[j].cfg_value);fwrite(buffer, 1, strlen(buffer), file);}}fclose(file);return 0;
}
/*** \description release cfg memory.* * \author sunsz* \date   2023/09/23 * */
void cfg_release() {cfg_debug("%s:%03d\n", __FUNCTION__, __LINE__);for (size_t i = 0; i < _cfg_config.cfg_section_num; i++) {if (_cfg_config.cfg_section[i].cfg_section_name != NULL) {free(_cfg_config.cfg_section[i].cfg_section_name);_cfg_config.cfg_section[i].cfg_section_name = NULL;}for (size_t j = 0; j < _cfg_config.cfg_section[i].cfg_data_num; j++) {if (_cfg_config.cfg_section[i].cfg_data[j].cfg_name != NULL) {free(_cfg_config.cfg_section[i].cfg_data[j].cfg_name);_cfg_config.cfg_section[i].cfg_data[j].cfg_name = NULL;}if (_cfg_config.cfg_section[i].cfg_data[j].cfg_value != NULL) {free(_cfg_config.cfg_section[i].cfg_data[j].cfg_value);_cfg_config.cfg_section[i].cfg_data[j].cfg_value = NULL;}}_cfg_config.cfg_section[i].cfg_data_num = 0;}_cfg_config.cfg_section_num = 0;
}
/*** \description read cfg.* * \author sunsz* \date   2023/09/23 * */
int cfg_load(const char *cfg_name) {static int u = 100;int e;*Prev_section = '\0';cfg_debug("%s:%03d\n", __FUNCTION__, __LINE__);memset(&_cfg_config, 0, sizeof(CFG_CONFIG));_cfg_config.cfg_section_num = 0;e = cfg_parse(cfg_name, GetConfig, &u);u++;return e;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/86016.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

短信登录功能如何实现?

简介&#xff1a; 在日常生活中我们登录/注册某些网站/APP是通常可以选择 密码登录和手机号登录。 为什么手机号发送后会有验证码返回呢&#xff1f; 网站如何识别我的验证码是否正确&#xff1f; 如果我的个人网站也想要实现短信登录功能&#xff0c;具体该如何实现&#xff1…

获取文件创建时间

版权声明 本文原创作者&#xff1a;谷哥的小弟作者博客地址&#xff1a;http://blog.csdn.net/lfdfhl Java源码 public void testGetFileTime() {try {String string "E://test.txt";File file new File(string);Path path file.toPath();BasicFileAttributes ba…

RedHat 服务器安装NGINX

参照官方文档&#xff1a;nginx: Linux packages 按顺序操作&#xff1a; 安装前提&#xff1a; sudo yum install yum-utils 设置yum仓库&#xff08;执行命令的时候会自动新建文件&#xff09;&#xff1a; sudo vi /etc/yum.repos.d/nginx.repo 粘贴下面的内容保存退出…

一个电子信息工程学生的历程和内心感想

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 一、我对大学三年专业课程的理解二、我为什么本科选择研究嵌入式这个方向&#xff1f;1.可以把理论变为实际应用——兴趣是最好的老师。2.嵌入式方向可以打的比赛非…

如何把利用paddlepaddle导出的json文件转化为yolo或者voc文件

目录 1. 修改源码&#xff0c;让模型能够生成出对于单个图像的标注。 2. 把数据转为yolo格式 3.把yolo格式转化为xml格式 这两天想偷懒&#xff0c;想让模型先在数据上标一遍&#xff0c;然后我再做修正&#xff0c;主要是图个省事。由于我们主要是利用paddle,模型也是基于p…

冒泡排序与选择排序(最low的两兄弟)

个人主页&#xff1a;Lei宝啊 愿所有美好如期而遇 前言&#xff1a; 在我们的生活中&#xff0c;无处不在用到排序&#xff0c;比如说成绩的排名&#xff0c;淘宝&#xff0c;京东等等商品在各个方面的排序&#xff0c;这样看来一个好的算 法很重要&#xff0c;接下来我们要先…

文件操作和IO

文章目录 一、文件系统二、文件类型三、文件系统操作3.1File类的属性3.2File类的构造方法3.3File类的方法 四、文件内容操作4.1Reader类里的函数4.2Writer类里的函数4.3InputStream类里的函数4.4OutputStream类里的函数4.5字节流转换为字符流 一、文件系统 1、操作系统会把很多…

【刷题-牛客】链表内指定区间反转

链表定区间翻转链表 题目链接题目描述核心思想详细图解代码实现复杂度分析 题目链接 链表内指定区间反转_牛客题霸_牛客网 (nowcoder.com) 题目描述 核心思想 遍历链表的过程中在进行原地翻转 [m,n]翻转区间记作子链表,找到子链表的 起始节点 left 和 终止节点 right记录在…

爬虫,初学者指南

第一篇&#xff1a;入门测速request模块的基本使用以www.douban.com为例 import requests url "http://www.douban.com" heards {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0…

组队竞赛(int溢出问题)

目录 一、题目 二、代码 &#xff08;一&#xff09;没有注意int溢出 &#xff08;二&#xff09;正确代码 1. long long sum0 2. #define int long long 3. 使用现成的sort函数 一、题目 二、代码 &#xff08;一&#xff09;没有注意int溢出 #include <iostream&g…

自动化测试的定位及一些思考

大家对自动化的理解&#xff0c;首先是想到Web UI自动化&#xff0c;这就为什么我一说自动化&#xff0c;公司一般就会有很多人反对&#xff0c;因为自动化的成本实在太高了&#xff0c;其实自动化是分为三个层面的&#xff08;UI层自动化、接口自动化、单元测试&#xff09;&a…

Sourcetree 无法打开/闪退问题

Sourcetree在某次开机以后无法打开或者是闪退。 Sourcetree是一款Git的可视化图形管理界面,提供了Windows和Mac的免费Git客户端,很方便的管理项目的代码版本 出现问题的环境 win11&#xff0c;sourcTree版本&#xff1a;3.4.12.0 在开始菜单搜索sourcetree&#xff0c;打开…

线上论坛之单元测试

对线上论坛进行单元测试的测试报告 源码地址&#xff1a;https://gitee.com/coisini-thirty-three/forum 一、用户部分&#xff08;UserServiceImplTest&#xff09; 1.创建普通用户 测试名称 createNormalUser() 测试源码 Test void createNormalUser() { // 构造用户 User …

为您的SSH提提速

SSH是运维和开发人员接触比较多的工具&#xff0c;一般用SSH来连接远程服务器&#xff0c;这个是我的一些免费客户和企业客户经常使用的场景&#xff0c;当然SSH除了远程连接之外&#xff0c;还有很多额外的用途&#xff0c;比如SSH本身是具备代理功能的&#xff0c;我们也有一…

【2023年研究生数学建模】E题解题思路

问题1 针对问题1.1&#xff0c;要求判断患者sub001至sub100发病后48小时内是否发生血肿扩张事件。对于此&#xff0c;先构建新表&#xff0c;记录每次检查的时间及血肿体积。采取遍历的方式识别48小时内是否出现血肿扩张事件&#xff0c;若发生血肿扩张&#xff0c;则记录入表…

如何写一份出色的毕业设计任务书

title: 如何写一份出色的毕业设计任务书 date: 2023-09-20 毕业设计任务书是每个毕业生必须面对的关键文档。它不仅是你完成毕业设计的路线图&#xff0c;还是导师评估你工作的依据。因此&#xff0c;撰写一份清晰、详细且具体的任务书至关重要。本文将向你介绍如何编写一份出色…

【Seata】seata的部署和集成

一、部署Seata的tc-server 1.下载 首先我们要下载seata-server包&#xff0c;地址在http://seata.io/zh-cn/blog/download.html 当然&#xff0c;课前资料也准备好了&#xff1a; 2.解压 在非中文目录解压缩这个zip包&#xff0c;其目录结构如下&#xff1a; 3.修改配置 修…

【MySQL】索引

索引 索引是帮助 MySQL 高效获取数据的数据结构&#xff08;有序&#xff09;。在数据之外&#xff0c;数据库系统还维护着满足特定查找算法的数据结构&#xff0c;这些数据结构以某种方式引用&#xff08;指向&#xff09;数据&#xff0c;这样就可以在这些数据结构上实现高级…

pyspark常用算子总结

欢迎关注微信公众号&#xff0c;更多优质内容会在微信公众号首发 1. pyspark中时间格式的数据转换为字符串格式的时间&#xff0c;示例代码 from datetime import datetimedate_obj datetime(2023, 7, 2) formatted_date date_obj.strftime("%Y-%m-%d %H:%M:%S")p…

go 线程限制数量 --chatGPT

问&#xff1a;runTask(names, limit), 遍历启动以names的子名称的工作线程 name测试打印&#xff0c;上限数量是limit, 要求打印所有names gpt: 你可以使用 Go 协程来实现 runTask 函数&#xff0c;该函数会遍历启动以 names 子名称的工作线程&#xff0c;并在达到上限数量 …