0
的爲什麼我能做到這一點Python的抱怨在「ntpath」沒有expanduser即使我導入os.path中
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os.path
>>> print(os.path)
<module 'ntpath' from 'C:\\Users\\odin\\AppData\\Local\\Programs\\Python\\Python35\\lib\\ntpath.py'>
>>> os.path.expanduser('~')
'C:\\Users\\odin'
在cmd.exe
,但不能做同樣的在我的腳本?
Traceback (most recent call last):
File "C:\Users\odin\DirectoryMonitorScript\a.py", line 94, in <module>
main()
File "C:\Users\odin\DirectoryMonitorScript\a.py", line 52, in main
with open(os.path.join(os.path.expanderuser('~'),'DirectoryMonitorScript','log','ScriptLog.txt'),'a') as f:
AttributeError: module 'ntpath' has no attribute 'expanderuser'
最少腳本示例:
import os.path
with open(os.path.join(os.path.expanderuser('~'),'DirectoryMonitorScript','log','ScriptLog.txt'),'a') as f:
# Do nothing
print('Nothing...')
這是Windows 10不知道我能提供什麼樣的其他細節。
就是這樣。愚蠢的錯誤,在工作中分心。 –
如果我們沒有犯錯,我們不會成爲人類;) –