2016-10-05 42 views
0

我想打開一個存儲在我的電腦上的網頁瀏覽器中的HTML文件,但出現錯誤(請參閱下文)。在網絡瀏覽器中從我的電腦打開HTML文件

from urllib import urlopen 
from webbrowser import open as webopen 
from os import getcwd 
from os.path import normpath 

我有這樣的代碼:

def open_html_file(): 
    path = normpath.abspath('New_News.html') 
    url = 'file://' + path 

    with open(path, 'w') as f: 
     f.write(html) 
    webopen.open(url) 

和我得到的代碼時運行這個錯誤:

AttributeError: 'function' object has no attribute 'abspath' 
+0

'os.path.normpath(os.path.abspath則( 'New_News.html'))' – furas

回答

0

normpath是一個函數,並沒有一個abspath屬性。 我覺得你的意思去做了:

from os.path import abspath 

path = abspath('New_News.html') 
相關問題