python 有多行注释运行报错

python 中写 这样的注释 用 vscode 运行会报错

#coding=utf-8

import json

from playwright.sync_api import sync_playwright

f = open('D:/threeday/backup-2.json',"r+")

urls = f.readlines()

print(json.loads(urls[0]))

with sync_playwright() as p:

browser = p.chromium.launch()

for url in urls[0]:

page = browser.new_page()

page.goto(url)

"""

λ python -m playwright install

Downloading chromium v844399 - 91 Mb [====================] 100% 0.0s

chromium v844399 downloaded to C:\Users\Administrator\AppData\Local\ms-playwright\chromium-844399

Downloading firefox v1225 - 75.1 Mb [====================] 100% 0.0s

firefox v1225 downloaded to C:\Users\Administrator\AppData\Local\ms-playwright\\firefox-1225

Downloading webkit v1423 - 38.2 Mb [====================] 100% 0.0s

webkit v1423 downloaded to C:\Users\Administrator\AppData\Local\ms-playwright\webkit-1423

"""

 python 有多行注释运行报错


回答:

字符串里的反斜杠(Windows路径)会被视为转义符,导致转义报错。
在引号前加上 r 可以避免转义,就不会报错了 ( r""" )。


回答:

好像是在注释中的路径会有这个问题

以上是 python 有多行注释运行报错 的全部内容, 来源链接: utcz.com/p/937922.html

回到顶部