无法读取yaml文件的更新版本

时间:2019-03-21 18:02:09

标签: python python-3.x yaml pyyaml

我正在像Python3中一样读取yaml文件:

def get_file():
    file_name = "file.yml"

    properties_stream = open(file_name, 'r')
    properties_file = yaml.safe_load(properties_stream)
    properties_stream.close()
    print(properties_file)
    return properties_file

当我通过添加键或删除文件的所有内容来更新file.yml时,第一次运行此代码时,“ print(properties_file)”语句仍保留yaml文件的内容。

有什么想法可能会发生这种情况吗?

1 个答案:

答案 0 :(得分:0)

Anthon是正确的。原来,我在不同子目录中的项目目录中有两个名称相同的文件夹,并且该文件夹正在从错误的文件中读取。