有时候正常没有问题的程序会报错,可能跟注释里面的中文也有关系 with open('photo1.jpg','rb') as file: data = file.read() #print(data) with open('photo5.jpg','wb') as newfile: newfile.write(data) 这个代码是没有问题的 with open('photo1.jpg','rb') as file: data = file.read() #print(data) with op
python3和python2的写法不一样具体如下: python3: with open(r'd:\ssss.txt','w',encoding='utf-8') as f: f.write(u'中文') python2中open方法是没有encoding这个参数的,如果像python3一样的写法会报异常:TypeError: 'encoding' is an invalid keyword argument for this function python2中需要加上: import sys