python - 一個(gè)程序中的切片問(wèn)題
問(wèn)題描述
下面標(biāo)記的地方,原文是這樣講的,#這個(gè)切片操作保證了event_text里面只保留一個(gè)屏幕的文字,但是操作過(guò)程中報(bào)錯(cuò)TypeError,
#coding: GBKimport pygame from pygame.locals import *from sys import exitpygame.init()SCREEN_SIZE = (640,480)screen = pygame.display.set_mode(SCREEN_SIZE,0,32)font = pygame.font.SysFont('arial',16)font_height = font.get_linesize()event_text = []while True: event = pygame.event.wait() event_text.append(str(event))event_text = event_text[-SCREEN_SIZE[1]/font_height:] #提示TypeError錯(cuò)誤,看不懂if event.type == QUIT:exit() screen.fill((0,255,0))y = SCREEN_SIZE[1]-font_heightfor text in reversed(event_text):screen.blit(font.render(text,True,(0,255,0)),(0,y))y -= font_height pygame.display.update()
問(wèn)題解答
回答1:你用的是Python 3嗎?在 Python 3里 a/b都是浮點(diǎn)數(shù),你修改成 SCREEN_SIZE[1]//font_height 吧!
相關(guān)文章:
1. php - 有關(guān)sql語(yǔ)句反向LIKE的處理2. fetch_field_direct()報(bào)錯(cuò)3. 在視圖里面寫php原生標(biāo)簽不是要迫不得已的情況才寫嗎4. 獲取上次登錄ip的原理是啥?5. 求救一下,用新版的phpstudy,數(shù)據(jù)庫(kù)過(guò)段時(shí)間會(huì)消失是什么情況?6. phpstudy v8打開(kāi)數(shù)據(jù)庫(kù)就出錯(cuò),而phpstudy 2018不會(huì)7. 為什么說(shuō)非對(duì)象調(diào)用成員函數(shù)fetch()8. 為什么點(diǎn)擊登陸沒(méi)反應(yīng)9. 請(qǐng)問(wèn)下tp6框架的緩存在哪里設(shè)置,或者說(shuō)關(guān)閉?10. mysql報(bào)錯(cuò) unknown column ’a.plat’ in ON clause
