我在Python中有以下代码。
"""
====================================================
This file provides a wrapper around the WebPageTest
APIs for starting a test and generating a har file
====================================================
"""
import json, urllib, os, ConfigParser
from pprint import pprint
from webPageTestConfigUtils import WebPageTestConfigUtils
class WebPageTestProcessor:
"""
=====================================================
Method to submit a test to WPT. Takes a url as input
for which you want to run the test.
=====================================================
"""
def submitTest(self,url):
response = None
if url is not None:
wptUrl = WebPageTestConfigUtils.getConfigValue('runTestURL')+"?f=json&url="+url+"&runs=3&video=1&web10=0&fvonly=1&mv=1&private=1&location=us_east_wptdriver:Chrome.DSL"
response = json.load(urllib.urlopen(wptUrl))
return response["data"]["testId"]
"""
======================================================
Method to check the status of the test submitted.
Takes a testId as input.
======================================================
"""
def checkTestStatus(self,testId):
response = None
if testId is not None:
wptUrl = WebPageTestConfigUtils.getConfigValue('testStatusURL')+"?f=json&test="+testId
response = json.load(urllib.urlopen(wptUrl))
return response
"""
======================================================
Method to get the HAR file. Takes the filepath to a
destination file and a testId for which to get a HAR.
Make sure you have write permissions to the file.
======================================================
"""
def getHarFile(self,filePath, testId):
if ( filePath is not None and testId is not None):
harUrl = WebPageTestConfigUtils.getConfigValue('harFileURL')+"?test="+testId
urllib.urlretrieve(harUrl,filePath)
我收到错误
IndentationError: expected an indented block
附近
"""
=====================================================
Method to submit a test to WPT. Takes a url as input
for which you want to run the test.
=====================================================
"""
为什么会因为我正确缩进代码而出现错误
答案 0 :(得分:4)
正如@PM 2Ring指出的那样,它意味着在OP中说docstring,附加信息:注释被视为空格,而不必与缩进对齐。
即使是 docstrings 也必须缩进,因为错误表明:
class WebPageTestProcessor:
"""
=====================================================
Method to submit a test to WPT. Takes a url as input
for which you want to run the test.
=====================================================
"""
def submitTest(self,url):
response = None
if url is not None:
wptUrl = WebPageTestConfigUtils.getConfigValue('runTestURL')+"?f=json&url="+url+"&runs=3&video=1&web10=0&fvonly=1&mv=1&private=1&location=us_east_wptdriver:Chrome.DSL"
response = json.load(urllib.urlopen(wptUrl))
return response["data"]["testId"]
...
答案 1 :(得分:0)
您必须在标签中输入文字字符串。你不能在同一级别的课程开始添加
class ABC:
"""
DOC STRING
"""
....
def xyz(self):
"""
DOC STRING FOR FUNCTION
"""
...