gpt4 book ai didi

python - 在 'with' 语句中返回危险吗?

转载 作者:行者123 更新时间:2023-12-04 03:50:38 26 4
gpt4 key购买 nike

<分区>

我需要返回一个文件的内容,这样做可以吗:

def foo(filePath):
with open(filePath) as f:
return json.load(f)

或者我应该这样做:

def foo(filePath):
with open(filePath) as f:
r = json.load(f)
return r

(当然我的功能还做其他事情,这是一个玩具模型)

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com