1
我刚刚学习如何使用Python进行编码,并且无法找到解决方案或答案,因为当我尝试读取刚才被写入它附带额外的字符。为什么我的Python代码在写入和读取文件时添加了额外的字符
代码
#-*-coding:utf-8-*-
from sys import argv
from os.path import exists
script, source, copy = argv
print "We'll be opening, reading, writing to and closing a file"
opensource = open(source)
readsource = opensource.read()
print readsource
print "Great. We opened and read file"
opencopy = open(copy, 'w+') #we want to write and read file
opencopy.write(readsource) #copy the contents of the source file
opencopy.read()
opensource.close()
opencopy.close()
输出
内容
test °D ΃ ø U ø U ` 6 ` 6 0M Ð
我在Windows 7 Professional 64bit上运行Python 2.7版本。