我正在寫一個腳本來計算某些特定單詞並給出了單詞的具體計數。如何在python中的類中打印'%d'和'%s'
我目前卡在打印數據,從類。
我的下一個任務是將這些值放入一個使用數據驅動框架的excel文件中。
這是我現在爲止已完成:
a = driver.page_source
soup = BeautifulSoup(a, "html.parser")
class counter_class:
def count(self, tittle, block_code):
blockcode_passed = block_code.count("Passed")
blockcode_blocked = block_code.count("Blocked")
blockcode_fail = block_code.count("Failed")
blockcode_retest = block_code.count("Retest")
blockcode_cannot_test = block_code.count("Connot Test")
blockcode_completed = block_code.count("Completed")
blockcode_passwc = block_code.count("Pass With Concern")
blockcode_untested = block_code.count("Untested")
print '%s' + ' ' + '%d' %(tittle,blockcode_passed)
print '%s' + ' ' + '%d' %(tittle,blockcode_fail)
print "Apps Gateway(Untested)" + ' ' + '%d' %(blockcode_untested)
print "Apps Gateway(Blocked)" + ' ' + '%d' %(blockcode_blocked)
print "Apps Gateway(Retest)" + ' ' + '%d' %(blockcode_retest)
print "Apps Gateway(Cannot Test)" + ' ' + '%d' %(blockcode_cannot_test)
print "Apps Gateway(Completed)" + ' ' + '%d' %(blockcode_completed)
print "Apps Gateway(Pass With Concern)" + ' ' + '%d' %(blockcode_passwc)
apps_gateway = soup.find_all("div", {"id":"group-3191427"})
apps_gateway_str = str(apps_gateway)
apps_gateway_obj=counter_class()
apps_gateway_obj.count("appsgateway",apps_gateway_str)
代碼作品,但代碼的第一部分的第二部分:
print '%s' + ' ' + '%d' %(tittle,blockcode_passed)
print '%s' + ' ' + '%d' %(tittle,blockcode_fail)
給我的錯誤:
print '%s' + ' ' + '%d' %(tittle,blockcode_passed)
TypeError: %d format: a number is required, not str
這做了我的工作。 –