gpt4 book ai didi

python - with ... : for . .. : 在一行中

转载 作者:太空宇宙 更新时间:2023-11-04 05:09:38 26 4
gpt4 key购买 nike

<分区>

作为初学者 python 程序员,我希望这是一个有简单解决方案的愚蠢错误(或缺乏理解):

/tmp> python3 -c 'with open("t","r") as f: for l in f: print(l)'
File "<string>", line 1
with open("t","r") as f: for l in f: print(l)
^
SyntaxError: invalid syntax

我可以在 oneline 中嵌入一个换行符,但试图理解为什么上面的方法不起作用

/tmp> python3 -c $'with open("t","r") as f:\n for l in f: print(l)'
Hi there

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