小编cza*_*doz的帖子

打印用户定义的类的对象列表

所以我有一个叫做的课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每个对象的值.有什么办法吗?

python

51
推荐指数
2
解决办法
5万
查看次数

Dynamodb2 Table.get_item()抛出ValidationException"键上的条件数无效"

我只是在DynamoDB中做一个简单的任务:

  1. 创建一个表,
  2. 添加一个项目
  3. 查询该项的表.

这是我正在使用的脚本:

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)

python boto amazon-dynamodb

11
推荐指数
1
解决办法
1万
查看次数

标签 统计

python ×2

amazon-dynamodb ×1

boto ×1