我有一個名爲nodes
的類的列表,它由Node類的實例組成。如何在Python中連接字符串到命令語句的末尾
class Node:
def __init__(self, bucketNumber ,colorONE, colorTWO,
colorTHREE, colorFOUR, colorFIVE):
self.bucket = bucketNumber # index
self.color1 = colorONE # quantity
self.color2 = colorTWO # quantity
self.color3 = colorTHREE # quantity
self.color4 = colorFOUR # quantity
self.color5 = colorFIVE # quantity
我問用戶他們想要什麼顏色編號。我希望能夠接受這個int並連接單詞「color」和數字。然後我希望能夠訪問該變量,如
valueE = (raw_input("Enter color number"))
valueE = int(valueE)
print nodes[0].color+valueE
我該如何做到這一點或類似的東西?
什麼是'nodes [0] .color'? – 2012-02-27 20:50:19