open()和with open()的区别
f = open(’/Users/michael/test.txt’, ‘w’)
f.write(‘Hello, world!’)
f.close()
你可以反复调用write()来写入文件,但是务必要调用f.close()来关闭文件。
with open
1,打开文件
with open ("文件名",“读写模式”) as file:
2,操作文件
***
自动关闭文件
html = requests.get(url,headers=header)
resultId = re.findall('sid="(.*?)">', html.text)
resultName = re.findall('<a href=".*?" target="play" title="(.*?)" sid=".*?">', html.text)
songId.extend(resultId)
songUrl = 'http://f2.htqyy.com/play7/{}'.format(songId[m])+'/mp3/9'