AttributeError: module 'shutil' has no attribute 'copyfileobj'
阿新 • • 發佈:2018-04-19
官方 .json eba con leo util line ttr imp
import shutil
#1.copyfileobj(源文件,目標文件) 將文件內容復制到另一個文件
shutil.copyfileobj(open(‘config.log‘,‘r‘),open(‘pic.json‘,‘a‘))
--------------------------------------------------------------------------------------------------------
以上代碼在執行的時候報了錯:
Traceback (most recent call last):
File "D:/Python/mypy/basic/shutil.py", line 4, in <module>
import shutil
File "D:\Python\mypy\basic\shutil.py", line 8, in <module>
shutil.copyfileobj(open(‘config.log‘,‘r‘),open(‘pic.json‘,‘a‘))
AttributeError: module ‘shutil‘ has no attribute ‘copyfileobj‘
--------------------------------------------------------------------------------------------------------------------------------------------------------
很不能理解,上網一查,居然有人跟我一樣,哈哈~
原因是這樣滴:
我的文件,名字是shutil.py
,而看上面的錯誤信息裏面,是用一個import shutil
,估計也是同樣錯誤的把我的腳本當作官方庫給錯誤引用了。
AttributeError: module 'shutil' has no attribute 'copyfileobj'