首页 > 其他分享 >open 一般的文件和yaml文件的区别

open 一般的文件和yaml文件的区别

时间:2023-08-16 16:00:18浏览次数:62  
标签:__ 文件 get yaml path open fo

一般的文件  读取的包含换行符  是数组格式

# open
def get_yaml(file_path):
    with open(file_path,encoding='utf-8') as fo:
        print(fo.readlines())
if __name__ == '__main__':
    get_yaml('../configs/evn.yaml')
    '''
    ['Login: # 登录整个模块\n', '  login: # 登录方法\n', '    url: /account/sLogin\n', '    method: post\n', '  logout: # 退出方法\n', '    url: /account/logout\n', '    method: post']

    '''

用yaml包 读取的数据 不包含换行符等  是字典格式

# 读取yaml 文件 获得字典类型的数据
import yaml
def get_yaml(yaml_path):
    with open(yaml_path,encoding='utf-8') as fo:
        yaml_data=yaml.safe_load(fo.read())
    return yaml_data
if __name__ == '__main__':
    print(get_yaml('../data/env.yaml'))
    '''
    {'Login': {'login': {'path': '/account/slogin', 'method': 'POST'}, 'logout': {'path': '/account/logout', 'method': 'POST'}}}

    '''

 

标签:__,文件,get,yaml,path,open,fo
From: https://www.cnblogs.com/haha1988/p/17635321.html

相关文章

  • 常用文件读取(python)
    CSV文件CSV(Comma-SeparatedValues)是一种常见的文本文件格式,用于存储结构化的数据。CSV文件中的数据是以逗号(或其他指定的分隔符)分隔的文本行,每一行表示一条记录,每个字段表示记录中的一个属性或值。读CSVimportcsvimportcodecsfile_name=""withopen(file_name,"r",en......
  • 前端文件转换
    file文件的拷贝和改名//复制文本域中的file文件并重命名letmyFile=newFile([file],"新文件的名字"]);bolb格式转base64格式functionblobToDataURL(blob,callback){letreader=newFileReader();reader.onload=function(){callback(reader.result);}re......
  • ITK 实例17 阈值水平集算法对脑部MHA文件进行三维分割
    1#include"itkImage.h"2#include"itkThresholdSegmentationLevelSetImageFilter.h"34#include"itkFastMarchingImageFilter.h"5#include"itkBinaryThresholdImageFilter.h"6#include"itkImageFile......
  • http实现大文件上传
    ​文件夹数据库处理逻辑public class DbFolder{    JSONObjectroot;       public DbFolder()    {        this.root= new JSONObject();        this.root.put("f_id", "");        this.root.put("f_nameLoc", "根......
  • ITK 实例11 边缘保留平滑滤波对脑部MHA文件进行三维滤波
    1#include"itkImage.h"2#include"itkCastImageFilter.h"3#include"itkCurvatureFlowImageFilter.h"4#include"itkImageFileReader.h"5#include"itkImageFileWriter.h"67intmain(intargc,char......
  • 判断文件是否是XML格式以及判断字符串是否是XML格式
    首先截取文件后缀名。后缀是XML文件再进入此判断,避免不必要的资源占用。/***判断一个文件是否是XML文件**@paramfile*@return*/privatestaticbooleanisXmlDocument(Filefile){booleanflag;try{DocumentBuilderFactoryfactory=Docume......
  • ITK 实例7 置信连接算法对脑部MHA文件进行三维分割
    在这个例子中使用前面例子中的代码,并设置图像的维数为3。应用梯度各向异性扩散来平滑图像。这个滤波器使用两个迭代器、一个值为0.05的timestep和一个值为3的conductance值,然后使用置信连接方式对平滑后的图像进行分割。使用的五个种子点的坐标分别为(118,85,92)......
  • ITK 实例9 孤立连接算法对脑部MHA文件进行三维分割
    1#include"itkIsolatedConnectedImageFilter.h"2#include"itkImage.h"3#include"itkCastImageFilter.h"4#include"itkCurvatureFlowImageFilter.h"5#include"itkImageFileReader.h"6#include"......
  • teamcenter 报错:java.lang.untimeExcept10n: B0M美异报导出板xlsx---》获即到用文件出
     解决方法:1、 2、用右键管理员权限来运行切换测试系统的BAT就可以了......
  • 使用 OpenTelemetry 构建可观测性 02 - 埋点
    这是讲解OpenTelemetry系列博客的第二篇。在上一篇博客中,我们介绍了OpenTelemetry是什么以及由什么组成。现在我们将讨论如何使用OTel准确收集遥测数据和链路追踪数据。手动埋点我们这里谈论“埋点”(代码插桩),是指通过技术手段采集链路追踪数据的行为。通常有两种方式:手动和......