当前位置: 首页 > news >正文

网站速成班有哪些专业哪个网站可以做身份核验

网站速成班有哪些专业,哪个网站可以做身份核验,丽水网站建设公司,烟台网络科技有限公司排名1、介绍config.ini文件 config.ini是一种配置文件#xff0c;常用于存储程序或系统的配置信息。它通常采用键值对的形式#xff0c;每一行表示一个配置项#xff0c;用等号#xff08;#xff09;将键和值分隔开。config.ini文件可以包含多个节#xff08;section#x…1、介绍config.ini文件 config.ini是一种配置文件常用于存储程序或系统的配置信息。它通常采用键值对的形式每一行表示一个配置项用等号将键和值分隔开。config.ini文件可以包含多个节section每个节可以包含多个配置项 2、创建config.ini文件  有两种方法 1、手动创建config.ini文件 2、在调用写入信息到config.ini文件时会自动创建 [database] host localhost port 5432 username myusername password mypassword[api] key myapikey url https://api.example.com ini结构         片段section对应 [database]         选项option对应 key1,相当于host         值value对应value1相当于locahost 3、写入 config.ini文件 import configparserdef create_config():config configparser.ConfigParser()# 设置database部分config[database] {host: localhost,port: 5432,username: myusername,password: mypassword}# 设置api部分config[api] {key: myapikey,url: https://api.example.com}# 写入到文件with open(config.ini, w) as configfile:config.write(configfile)create_config() 这段代码创建了一个名为 config.ini 的文件并填充了它与我们在之前的INI文件示例中看到的相同的值。   4、读取config.ini文件 简单版 import configparserdef read_config():config configparser.ConfigParser()config.read(config.ini)# 读取数据库配置db_host config.get(database, host)db_port config.get(database, port)db_username config.get(database, username)db_password config.get(database, password)# 读取API配置api_key config.get(api, key)api_url config.get(api, url)return db_host, db_port, db_username, db_password, api_key, api_urldb_host, db_port, db_username, db_password, api_key, api_url read_config()print(Database 数据:) print(fHost: {db_host}) print(fPort: {db_port}) print(fUsername: {db_username}) print(fPassword: {db_password})print(\nAPI 数据:) print(fKey: {api_key}) print(fURL: {api_url}) Database 数据: Host: localhost Port: 5432 Username: myusername Password: mypasswordAPI 数据: Key: myapikey URL: https://api.example.comProcess finished with xit code 0 优化版 import configparser import os# 读取配置文件 def read_config():# 获取当前文件所在目录 root_dir os.path.dirname(os.path.dirname(__file__))# 组装config.ini路径也可以直接写配置文件的具体路径不用自动获取config_dir os.path.join(root_dir, config, config.ini)# 创建configparser对象cf configparser.ConfigParser()# 读取config.inicf.read(config_dir, encodingutf-8)return cfcf read_config() api_url cf.get(api, url) # 注意端口要用getint方法获取 database_port cf.getint(database, port) print(api_url) print(database_port) https://api.example.com 5432Process finished with exit code 0 5、总结 读取配置文件的常用方法 # 创建configparser对象cf configparser.ConfigParser()# 读取配置文件 常用的方法介绍cf.read(filename) # 读取文件返回filename的listcf.sections() # 获取配置文件中所有sections的listcf.options(section) # 获取指定section的键值listcf.items(section) # 获取指定section下所有的键值对listcf.get(section, key) # 获取指定section下指定key的value值 返回strcf.getint(section, key) # 获取指定sections下指定key的value值 返回intcf.getfloat(section, key) # 获取指定sections下指定key的value值 返回floatcf.getboolean(section, key) # 获取指定sections下指定key的value值 返回booleancf.has_section(section) # 获取是否包含某个section返回booleancf.has_option(sectionkey) # 获取是否包含某个section的某个键返回boolean写入配置文件的常用方法 # 写入配置文件 常用方法介绍 cf configparser.ConfigParser() # 实例化对象cf.read(self.filename) # 读取文件如果是重新写入覆盖原有内容不需要读取 cf.add_section(section) # 添加sections值cf.set(section, option, value) # 在指定的sections中添加键值对cf.remove_section(section) # 移除sections 需要先cf.read(filename)cf.remove_option(section, option) # 移除指定sections下的options 需要先cf.read(filename)样例介绍 # 样例介绍 class WriteConfig():写入config文件def __init__(self, filename, filepathrD:\python_file\boke\config):self.filename filenameos.chdir(filepath)self.cf configparser.ConfigParser()self.cf.read(self.filename) # 如果修改则必须读原文件def _with_file(self):# write to filewith open(self.filename, w) as f:self.cf.write(f)def add_section(self, section):# 写入section值self.cf.add_section(section)self._with_file()def set_options(self,section, option, valueNone):写入option值self.cf.set(section, option, value)self._with_file()def remove_section(self, section):移除section值self.cf.remove_section(section)self._with_file()def remove_option(self, section, option):移除option值self.cf.remove_option(section, option)self._with_file()
http://www.zqtcl.cn/news/852115/

相关文章:

  • 校园网站建设资金来源有wordpress权重
  • 魔站网站开发wordpress 3.3.1
  • 东莞个人免费建网站网站后台管理系统 asp
  • 呼和浩特网站制作 建设wordpress怎么改中文
  • 银医网站建设方案公司网站模板免费下载
  • 优秀网站设计案例中国网站建设东莞公司
  • 自己的公网ip可以做网站网页设计与制作课程思政建设内容
  • 静态网站 搜索搭建织梦网站教程
  • idc 网站备案手机电脑网站建设短视频
  • 做搜狗pc网站优化快速亚马逊云搭建WordPress
  • 免费的建网站软件2020做seo还有出路吗
  • 宁波三优互动网站建设公司怎么样网站建设公司管理流程图
  • 网站内文章外链如何做创新设计
  • 西安做网站公网站做友链有行业要求吗
  • 做现金贷网站的公司软件开发设计文档
  • 数据做图网站表示商业网站的域名
  • 网站备案单位备案老域名
  • 黔西南州建设局网站网站建设流程的过程
  • 河南龙王建设集团网站沈阳专业建站
  • 百度网盘app下载安装手机版百度排名优化咨询电话
  • 网站微信公众号链接怎么做免费访问国外网站的应用
  • 东莞网站搜索排名wordpress 小工具居中
  • 网上商城网站源码网站建站中关键字搜索怎么弄
  • 房地产开发公司网站源代码 墨绿色风格河北省建设项目环保备案网站
  • 有没有做机械加工的网站企业网站建站企业
  • 网站自创重庆宣传片制作
  • 如何做美发店网站世界上网站做的好的例子
  • 不会代码可以做网站维护吗成版年蝴蝶视频app免费
  • html5手机论坛网站模板支付商城网站制作
  • 自己主机做多个网站网站备案和服务器备案