如果未指定路径名,则open()指向的目录或路径

时间:2019-07-17 14:54:43

标签: python directory

如果open()方法中的路径只是一个文件名,它指向的默认目录是什么?

def write_dicts_to_file(path,data):
    with open(path,'wb') as fp:
        for d in data:
            fp.write(json.dumps(d).encode('utf-8'))
            fp.write("\n".encode('utf-8'))
write_dicts_to_file("train.json",training_data)

1 个答案:

答案 0 :(得分:0)

您从中调用write_dicts_to_file()方法的python文件的目录。