python1_Python-如何返回-1?

此方法是否应该返回-1?

def tree_value(self, team, x, y):

if team == NO_TEAM or self.team_sees_tree[team, x, y]:

return int(self.tree[x, y])

else:

return TREE_NONE

设定:

import numpypy as np

TREE_NONE = 255

NO_TEAM = -1

self.tree= np.empty((dim, dim), np.uint8)

for i in xrange(dim):

for j in xrange(dim):

self.tree[i, j] = TREE_NONE

self.team_sees_tree = np.zeros((16, dim, dim), np.bool_)

在正常操作期间,树值设置为0-15(团队编号)或TREE_NONE(255).即使将它们意外地设置为-1(NO_TEAM),也应等于255作为uint8.

调用获得-1的tree_value():

data = [(self.Tiles.tree_value(COLOR_NONE, x, y),

self.Tiles.mountain_value(x, y)) for (x, y) in coords]

str = ""

try:

for (t, m) in data:

str += chr(t) + chr(m)

except ValueError as e:

print data

# [(255, 0), (255, 0), (255, 0), (255, 0), (255, 0), (-1, 0), (255, 0)]

print e

# ValueError: character code not in range(256)

无法准确地重现此问题,但是我的服务器每小时要打两次.在Ubuntu 12.04 32位上最近运行的PyPy最近每晚构建(pypy-c-jit-64927-e0ba4acfd3c2-linux.tar.bz2).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值