当前位置: 首页>>代码示例>>Python>>正文


Python field.Field类代码示例

本文整理汇总了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
开发者ID:andyzt,项目名称:tceh,代码行数:7,代码来源:players.py

示例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))
开发者ID:mikoim,项目名称:funstuff,代码行数:35,代码来源:tests.py

示例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
开发者ID:mianhe,项目名称:packetPaPa,代码行数:7,代码来源:tlv.py

示例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
开发者ID:edwardsmith999,项目名称:pyDataView,代码行数:7,代码来源:openfoamfields.py

示例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)
开发者ID:jergason,项目名称:pd_controller,代码行数:32,代码来源:agent0.py

示例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
开发者ID:Rad0x6f,项目名称:kpro9,代码行数:28,代码来源:dissector.py

示例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()
开发者ID:kurtisz,项目名称:ConicBlockingSets,代码行数:29,代码来源:matrix_generation.py

示例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"
开发者ID:leonardleonard,项目名称:spyder,代码行数:59,代码来源:document.py

示例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
开发者ID:cameronbriar,项目名称:curses,代码行数:59,代码来源:saver.py

示例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
开发者ID:edwardsmith999,项目名称:pyDataView,代码行数:8,代码来源:channelflowfields.py

示例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)
开发者ID:amerberg,项目名称:PDFMetadataExtractor,代码行数:8,代码来源:fields.py

示例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()
开发者ID:msarch,项目名称:py,代码行数:8,代码来源:gui.py

示例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)
开发者ID:fangohr,项目名称:oommf-python,代码行数:9,代码来源:field_test.py

示例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
开发者ID:bjornedstrom,项目名称:elliptic-curve-chemistry-set,代码行数:9,代码来源:eddsa.py

示例15: __init__

 def __init__(self):
     """
     EXAMPLES::
     
         sage: ContinuedFractionField()
         Field of all continued fractions
     """
     Field.__init__(self, self)
     self._assign_names(('x'),normalize=False)
开发者ID:dagss,项目名称:sage,代码行数:9,代码来源:contfrac.py


注:本文中的field.Field类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。