with open写入数据的时候 是只能创建最后一个文件吗

with open( '/path/to/file', 'r' ) as f:
print( f.read() )

比如说这段代码里面,如果path,to这两个文件夹不存在的话,就会显示无法创建文件夹嘛?不会自动创建的是吧?

if not os.path.exists( '/path/to/'):
      os.makedirs(path)
with open( '/path/to/file', 'a' ) as f:
print( f.read() )

注意,,a这个参数就是自动创建

https://blog.csdn.net/Fantasy_Virgo/article/details/82315727