简体   繁体   English

打开 HTML 文件、Python 的路径时出现 Unicode 错误。 我该如何解决?

[英]Unicode error for opening path towards HTML file, Python. How would I fix?

I'm using Folium to create a map and display it as an HTML file.我正在使用Folium创建地图并将其显示为 HTML 文件。 I created a function to open up the HTML file with the given path.我创建了一个函数来打开具有给定路径的 HTML 文件。

import webbrowser
import folium
from folium import plugins
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from IPython.core.display import display, HTML

m = folium.Map([52.5, 2], zoom_start=5.5)
display(m)
m.save('map.html')


def auto_open(path):
    html_page = f'{path}'
    m.save(html_page)
    # open in browser.
    new = 2
    webbrowser.open(html_page, new=new)


auto_open('C:\Users\Student\PycharmProjects\World Map')

I'm getting the error code: auto_open('C:\\Users\\Student\\PycharmProjects\\World Map') ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \\UXXXXXXXX escape我收到错误代码: auto_open('C:\\Users\\Student\\PycharmProjects\\World Map') ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \\UXXXXXXXX escape

It's the correct path to the html file.这是 html 文件的正确路径。 But I'm not understanding the error at all.但我根本不理解这个错误。 I would love the help.我很乐意帮助。 Any more information I can give let me know.我可以提供的更多信息让我知道。 Thank you.谢谢你。

Edit: I added in the \\\\ to fix the error, but now I'm getting, I've done this and it pops up:编辑:我添加了\\\\来修复错误,但现在我明白了,我已经完成了它并弹出:

File "C:\\Python\\Python37\\lib\\site-packages\\branca\\element.py", line 161, in save fid = open(outfile, 'wb') PermissionError: [Errno 13] Permission denied:'C:\\\\Users\\\\Student\\\\PycharmProjects\\\\World Map'

You need nothing but doubled parentheses to replace the single ones :你只需要双括号来替换单个括号:

auto_open('C:\\Users\\Student\\PycharmProjects\\World Map')

PS: Don't forget to close up the target file( outfile ) before re-run in order not to prevent getting [Errno 13] PS:不要忘记在重新运行之前关闭目标文件( outfile ),以免防止出现[Errno 13]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM