python open() 遇到的问题请教
lc_path = D:\PycharmProjectsfor com_num in range(33, 3932, 1):with open("f{com_num}.cis", "wb") as cisf:
lc_path 这个是生成一个地址,怎样加入open里面,也就是指定地址存放,谢谢 没看懂,小白一个,知晓了可以踢我一下 谢谢 怎样加入open里面 试试:
with open(r"f{com_num}.cis", "wb") as cisf: open变量用变量就行了 open("f%s.cis" % com_num, "wb") open里的参数实质上是字符串,对这个字符串操作就可以了
``` python3
for com_num in range(33, 3932, 1):
lc_path = "D:\PycharmProjects"+str(com_num)
#do something
``` with open(f"{lc_path} {com_num}.cis", "wb") as cisf: 在f-string中{}内的变量会自动替换
也可以用%自行拼接with open("%s %s.cis" % (lc_path,com_num), "wb") as cisf:
当然format也是可以的 with open("{}{}.cis".format(lc_path,com_num), "wb") as cisf: 楼主的这个怎么断句。。。我怎么突然看不懂了。。。
页:
[1]
2