每行的末尾都有一个“+\”:
def buildRequestXml(detailLevel, viewAllNodes):
requestXml = "<?xml version='1.0' encoding='utf-8'?>"+\
"<AddItemRequest xmlns=\"urn:ebay:apis:eBLBaseComponents\">"+\
"<RequesterCredentials><eBayAuthToken>" + userToken + "</eBayAuthToken></RequesterCredentials>"
if (detailLevel != ""):
requestXml = requestXml + "<DetailLevel>" + detailLevel + "</DetailLevel>"
requestXml = requestXml + "<Item>"+\
"<BuyItNowPrice>10.0</BuyItNowPrice>"+\
"<Country>US</Country>"+\
"<Currency>USD</Currency>"+\
"<Description>This is a test.</Description>"+\
"<ListingDuration>Days_7</ListingDuration>"+\
"<Location>San Jose, CA</Location>"+\
"<PaymentMethods>PaymentSeeDescription</PaymentMethods>"+\
"<PrimaryCategory>"+\
" <CategoryID>357</CategoryID>"+\
"</PrimaryCategory>"+\
"<Quantity>1</Quantity>"+\
"<StartPrice>1.0</StartPrice>"+\
"<ShippingTermsInDescription>True</ShippingTermsInDescription>"+\
"<Title>Test item title</Title>"+\
"</Item>"+\
"</AddItemRequest>"
return requestXml
\
是一个行延续字符,意味着下一行是当前行的延续但是,根据PEP-0008样式指南,最好使用括号隐式继续:
用括号代替
\
:通过将表达式包装在括号中,Python知道如何继续下一行。你知道吗
\表示行的延续。你知道吗
这是一个行延拓运算符。基本上,它是对不可见的换行符进行转义,迫使Python将所有这些都视为一行。你知道吗
例如
与相同
相关问题 更多 >
编程相关推荐