本文整理汇总了Python中field.Field类的典型用法代码示例。如果您正苦于以下问题:Python Field类的具体用法?Python Field怎么用?Python Field使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Field类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, name, size):
self.name = name
self.ships = []
self.field_size = size
self.my_field = Field(size, is_enemy=False)
self.enemy_field = Field(size, is_enemy=True)
self.verbose = True
示例2: FieldTests
class FieldTests(unittest.TestCase):
def setUp(self):
self.__x = random.randint(2, 128)
self.__y = random.randint(2, 128)
self.__field = Field(self.__y, self.__x)
def test_zero(self):
self.assertFalse(Field(0, 0).is_correct(0, 0))
def test_size(self):
self.assertEqual(self.__field.x, self.__x)
self.assertEqual(self.__field.y, self.__y)
def test_basic(self):
n = random.random()
x = random.randint(0, self.__x - 1)
y = random.randint(0, self.__y - 1)
self.__field[y][x] = n
self.assertEqual(self.__field[y][x], n)
def test_border(self):
self.__field[0][0] = 0
self.__field[self.__y - 1][self.__x - 1] = 0
def test_method_is_correct(self):
x = random.randint(0, self.__x - 1)
y = random.randint(0, self.__y - 1)
self.assertTrue(self.__field.is_correct(0, 0))
self.assertTrue(self.__field.is_correct(y, x))
self.assertTrue(not self.__field.is_correct(-1, 0))
self.assertTrue(not self.__field.is_correct(0, -1))
self.assertTrue(not self.__field.is_correct(self.__y, 0))
self.assertTrue(not self.__field.is_correct(0, self.__x))
示例3: __init__
def __init__(self,name,type_byte_nr=1,length_byte_nr=1,length_compensation=0,type_=0,value=''):
Field.__init__(self, name, value)
self._type_byte_nr = type_byte_nr
self._length_byte_nr = length_byte_nr
self._type = type_
self._length_compensation = length_compensation
self._length = len(value) + length_compensation
示例4: __init__
def __init__(self, fdir, fname, parallel_run=None):
Raw = OpenFOAM_RawData(fdir, fname,
self.nperbin,
parallel_run=parallel_run)
Field.__init__(self, Raw)
self.axislabels = ['x','y','z']
self.plotfreq = self.Raw.Nave
示例5: tick
def tick(self, time_diff):
"""Some time has passed; decide what to do next."""
mytanks, othertanks, flags, shots = self.bzrc.get_lots_o_stuff()
self.mytanks = mytanks
self.flags = flags
# We only care about our enemy's flag
enemy_flag = None
for flag in self.flags:
# print("flag color: %s x: %f y: %f" % (flag.color, flag.x, flag.y))
if flag.color == self.enemy:
# print("enemy found, and it is %s" % flag.color)
enemy_flag = flag
# Flag is the goal, so it creates an attractive field
obstacles = self.bzrc.get_obstacles()
fields = self.repulsive_and_tangential_fields_from_obstacles(obstacles)
# fields = []
attractive_field = Field(enemy_flag.x, enemy_flag.y, 5, 300)
attractive_field.kind = 'attractive'
for tank in self.mytanks:
# print("tank angle is %f x is %f y is %f" % (tank.angle, tank.x, tank.y))
#if this tank has the flag, then its attractive field is the home base
if tank.flag == self.enemy:
attractive_field = Field((self.base.corner1_x + self.base.corner3_x) / 2.0, (self.base.corner1_y + self.base.corner3_y) / 2.0, 5, 300)
attractive_field.kind = 'attractive'
fields.append(attractive_field)
self.bzrc.angvel(tank.index, self.calculate_angvel(tank, fields))
#speed depends on how far away we are?
#just ignore that for now, see if it works.
self.bzrc.speed(tank.index, self.calculate_speed(tank, fields))
self.bzrc.shoot(tank.index)
示例6: __init__
def __init__(self, platforms):
"""Create a new delegator instance.
'platforms' is a set of all platforms to support
"""
super().__init__('luastructs', Platform.mappings['default'], None)
self.platforms = platforms
self.field_var = 'f.'
self.description = 'Lua C Structs'
self.dissectors = {self.platform.name: self}
self.var = create_lua_var('delegator')
self.table_var = create_lua_var('dissector_table')
self.id_table = create_lua_var('message_ids')
self.sizes_table = create_lua_var('dissector_sizes')
self.msg_var = create_lua_var('msg_node')
# Add fields, don't change sizes!
endian = Platform.big
self.add_field(Field('Version', 'uint8', 1, 0, endian))
values = {p.flag: p.name for name, p in self.platforms.items()}
field = Field('Flags', 'uint8', 1, 0, endian)
field.set_list_validation(values)
self.add_field(field)
self.add_field(Field('Message', 'uint16', 2, 0, endian))
self.add_field(Field('Message length', 'uint32', 4, 0, endian))
self.version, self.flags, self.msg_id, self.length = self.children
示例7: generate_matrix
def generate_matrix(q, number_processes = 35):
field = Field(q)
two_powers = [2 ** (q - i) for i in xrange(q + 1)]
with Manager() as manager:
A = manager.dict() # where we store the row integers
amount = lambda : len(A) # I use this to print out how many rows we have generated periodically
def append(x):
if x in A:
return 0
A[x] = True
return 1
#append = lambda x : A.__setitem__(x, True)
is_new = lambda x : not A.__contains__(x) # to avoid duplicate entries
# we don't need the a = 0, b = q - 1 case because it requires setting the 0th column (0 * (q-1)) which has already been chosen
a = q - 1
# generate all the numerators quickly
numerators = [[field.add(field.multiply(a, t), c) for t in field.trace()] for c in field]
bs = range(q - 3) + [q - 1] # all the b values we need
_distribute(lambda bs : _make_and_start_process(bs, a, field, numerators, append, is_new, two_powers, amount), bs, number_processes)
# start all the processes and then wait for them to finish
# the keys of the dictionary represent the row integers for the problem
return A.keys()
示例8: parseJsonPage
def parseJsonPage(self, site, doc, listurl):
try:
doc = json.loads(doc, encoding=site.getCharset())
item = self.listRule.getEntryItem()
if item and item in doc:
data = doc[item]
else:
data = doc
urlParent = self.listRule.getContentUrl()
extrarules = self.listRule.extrarules
if isinstance(data, list) and urlParent:
for _data in data:
if urlParent in _data:
link = urlparse.urljoin(listurl, _data[urlParent])
guid = md5(link).hexdigest()
_item = Item({
"type" : self.seed_type,
"images" : []
})
#取出需要的key数据
for field_name, _rule, fetch_all, page_type in extrarules:
field = Field(name = field_name, rule=_rule)
if _rule in _data:
value = _data[_rule]
if is_image(value):
_item["images"].append(value)
field.value = value
_item[field["name"]] = field
if (link is not None):
_item['url'] = link
# get item guid
if self.guid_rule:
guid = self.getItemGUID(_item)
elif self.seed["dont_craw_content"]:
self.guid_rule = []
for f in _item.fields:
self.guid_rule.append(_item[f]["id"])
guid = self.getItemGUID(_item)
self.guid_rule = None
else:
self.guid_rule = "url"
guid = self.getItemGUID(_item)
self.guid_rule = None
self.items[guid] = _item
else:
if isinstance(self.items, dict):
self.items = [];
self.items.append(data)
except:
raise "Cant parse json file"
示例9: Saver
class Saver():
def __init__(self, balls=int(random.random() * 100), trail=" "):
self.field = Field(title="Term Saver")
self.balls = [Ball(x=int(random.random() * self.field.x-1)+1, y=int(random.random() * self.field.y-1)+1) for x in range(balls)]
self.speed = 0.009
self.trail = trail
return
def update(self):
for ball in self.balls:
hitWall = self.walled(ball)
if hitWall: # wall collision
ball.bounce(hitWall)
# ball collision
self.clearTrail(ball, self.trail, True)
ball.move()
self.field.write_at(item=ball.image, coords=ball.getPosition())
# clear the field randomly (.1% chance)
if random.choice(range(1000)) == 1:
self.field.clear()
self.field.deploy()
return
def walled(self, ball):
direction = []
if ball.x < 1:
direction.append('right')
elif ball.x >= self.field.x-1:
direction.append('left')
if ball.y < 1:
direction.append('down')
elif ball.y >= self.field.y-1:
direction.append('up')
if len(direction):
return ' '.join(direction)
return None
def run(self):
run = 1
while run:
c = self.field.display.getch()
if c == ord('q'):
run = 0
self.update()
time.sleep(self.speed)
self.field.destroy()
return
def clearTrail(self, obj, remains=" ", centered=False):
for i in range(len(obj.image)):
self.field.write_at(item=remains, coords=[obj.x+i, obj.y], centered=centered)
return
示例10: __init__
def __init__(self,fdir,rectype='bins'):
self.vField = Channelflow_vField(fdir)
self.strainField = Channelflow_strainField(fdir)
Field.__init__(self,self.vField.Raw)
self.inherit_parameters(self.strainField)
self.labels = ["mag"]
self.nperbin = 1
示例11: __init__
def __init__(self, settings, name, data, allowed_range=None):
"""Set the allowed range if specified."""
self.start = None
self.end = None
if allowed_range is not None:
self.start, self.end = allowed_range
Field.__init__(self, settings, name, data)
示例12: frame_paint
def frame_paint(self,dt):
"""Clear the current OpenGL context, calls actor's paint_all method
"""
if not self.paused:
self.gl_clear()
Field.paint()
if self.show_fps:
self.pcd.draw()
示例13: test_domain_centre
def test_domain_centre(self):
cmin = (-18.5, 5, 0)
cmax = (10, 10, 10)
d = (0.1, 0.25, 2)
name = 'test_field'
f = Field(cmin, cmax, d, dim=2, name=name)
assert f.domain_centre() == (-4.25, 7.5, 5)
示例14: __init__
def __init__(self):
field = Field(2**255 - 19)
ed25519 = TwistedEdwardsCurve(-1, field.div(-121665, 121666), field)
base_point = (15112221349535400772501151409588531511454012693041857206046113283949847762202L,
46316835694926478169428394003475163141307993866256225615783033603165251855960L)
self.curve = ed25519
self.bp = base_point
示例15: __init__
def __init__(self):
"""
EXAMPLES::
sage: ContinuedFractionField()
Field of all continued fractions
"""
Field.__init__(self, self)
self._assign_names(('x'),normalize=False)