所以我有一个叫做的课Vertex.
class Vertex:
'''
This class is the vertex class. It represents a vertex.
'''
def __init__(self, label):
self.label = label
self.neighbours = []
def __str__(self):
return("Vertex "+str(self.label)+":"+str(self.neighbours))
Run Code Online (Sandbox Code Playgroud)
我想打印这个类的对象列表,如下所示:
x = [Vertex(1), Vertex(2)]
print x
Run Code Online (Sandbox Code Playgroud)
但它显示我这样的输出:
[<__main__.Vertex instance at 0xb76ed84c>, <__main__.Vertex instance at 0xb76ed86c>]
Run Code Online (Sandbox Code Playgroud)
实际上,我想打印Vertex.label每个对象的值.有什么办法吗?
我只是在DynamoDB中做一个简单的任务:
这是我正在使用的脚本:
from boto.dynamodb2.fields import HashKey, RangeKey, AllIndex, GlobalAllIndex
from boto.dynamodb2.items import Item
from boto.dynamodb2.layer1 import DynamoDBConnection
from boto.dynamodb2.table import Table
# Using DynamoDB Local
conn = DynamoDBConnection(host='localhost', port=8000, is_secure=False)
## ----- Create a table -----
throughput = {
'write': 1,
'read': 1
}
schema = [
HashKey('id'),
RangeKey('rating')
]
local_indexes = [
AllIndex('local_all_index_seats', parts=[
HashKey('id'),
RangeKey('seats')
])
]
global_indexes = [
GlobalAllIndex('global_all_index_color', parts=[
HashKey('color'),
RangeKey('rating')
])
]
new_table = Table.create('items', schema=schema, indexes=local_indexes,
global_indexes=global_indexes, connection=conn,
throughput=throughput)
print …Run Code Online (Sandbox Code Playgroud)