python类FloatType()的实例源码

DBAdapters.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, dbname=constants.CDefSQLiteDBName, identify=None, resetDB=False,
                resetIdentify=True, frequency=constants.CDefSQLiteStatsGenFreq,
                commit_freq=constants.CDefSQLiteStatsCommitFreq):
      """ The creator of the DBSQLite Class """

      super(DBSQLite, self).__init__(frequency, identify)

      self.sqlite3mod = None
      self.connection = None
      self.resetDB = resetDB
      self.resetIdentify = resetIdentify
      self.dbName = dbname
      self.typeDict = {types.FloatType: "real"}
      self.cursorPool = None
      self.commitFreq = commit_freq
DBAdapters.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, dbname=constants.CDefSQLiteDBName, identify=None, resetDB=False,
                resetIdentify=True, frequency=constants.CDefSQLiteStatsGenFreq,
                commit_freq=constants.CDefSQLiteStatsCommitFreq):
      """ The creator of the DBSQLite Class """

      super(DBSQLite, self).__init__(frequency, identify)

      self.sqlite3mod = None
      self.connection = None
      self.resetDB = resetDB
      self.resetIdentify = resetIdentify
      self.dbName = dbname
      self.typeDict = {types.FloatType: "real"}
      self.cursorPool = None
      self.commitFreq = commit_freq
sparse_vector_class.py 文件源码 项目:NLP.py 作者: PythonOptimizers 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __rpow__(self, other):
        """Use each element of sparse vector as power of base."""
        if not isSparseVector(self):
            raise TypeError("Argument must be a SparseVector")
        if not isinstance(other, types.IntType) and \
           not isinstance(other, types.LongType) and \
           not isinstance(other, types.FloatType):
                raise TypeError("Power must be numeric")
        rv = SparseVector(self.n, {})
        for k in self.values.keys():
            rv[k] = math.pow(other, self[k])
        return rv
ikpdb.py 文件源码 项目:ikpdb 作者: audaxis 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def object_properties_count(self, o):
        """ returns the number of user browsable properties of an object. """
        o_type = type(o)
        if isinstance(o, (types.DictType, types.ListType, types.TupleType, set,)):
            return len(o)
        elif isinstance(o, (types.NoneType, types.BooleanType, types.FloatType, 
                            types.UnicodeType, types.FloatType, types.IntType, 
                            types.StringType, types.LongType, types.ModuleType, 
                            types.MethodType, types.FunctionType,)):
            return 0
        else:
            # Following lines are used to debug variables members browsing
            # and counting
            # if False and str(o_type) == "<class 'socket._socketobject'>":
            #     print "@378"
            #     print dir(o)
            #     print "hasattr(o, '__dict__')=%s" % hasattr(o,'__dict__')
            #     count = 0
            #     if hasattr(o, '__dict__'):
            #         for m_name, m_value in o.__dict__.iteritems():
            #             if m_name.startswith('__'):
            #                 print "    %s=>False" % (m_name,)
            #                 continue
            #             if type(m_value) in (types.ModuleType, types.MethodType, types.FunctionType,):
            #                 print "    %s=>False" % (m_name,)
            #                 continue
            #             print "    %s=>True" % (m_name,)
            #             count +=1
            #     print "    %s => %s = %s" % (o, count, dir(o),)
            # else:
            if hasattr(o, '__dict__'):
                count = len([m_name for m_name, m_value in o.__dict__.iteritems()
                              if not m_name.startswith('__') 
                                and not type(m_value) in (types.ModuleType, 
                                                          types.MethodType, 
                                                          types.FunctionType,) ])
            else:
                count = 0
            return count
Elements.py 文件源码 项目:rekall-agent-server 作者: rekall-innovations 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def AddRow( self, *cells ) :
        height = None
        if isinstance( cells[ 0 ], (IntType, FloatType, LongType) ):
            height = int( cells[ 0 ] )
            cells  = cells[ 1 : ]

        #  make sure all of the spans add up to the number of columns
        #  otherwise the table will get corrupted
        if self.ColumnCount != sum( [ cell.Span for cell in cells ] ) :
            raise Exception( 'ColumnCount != the total of this row\'s cell.Spans.' )

        self.Rows.append( ( height, cells ) )
Elements.py 文件源码 项目:slugiot-client 作者: slugiot 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def AddRow( self, *cells ) :
        height = None
        if isinstance( cells[ 0 ], (IntType, FloatType, LongType) ):
            height = int( cells[ 0 ] )
            cells  = cells[ 1 : ]

        #  make sure all of the spans add up to the number of columns
        #  otherwise the table will get corrupted
        if self.ColumnCount != sum( [ cell.Span for cell in cells ] ) :
            raise Exception( 'ColumnCount != the total of this row\'s cell.Spans.' )

        self.Rows.append( ( height, cells ) )
timetest.py 文件源码 项目:rdiff-backup 作者: sol1 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def testConversion(self):
        """test timetostring and stringtotime"""
        Time.setcurtime()
        assert type(Time.curtime) is types.FloatType or types.LongType
        assert type(Time.curtimestr) is types.StringType
        assert (Time.cmp(int(Time.curtime), Time.curtimestr) == 0 or
                Time.cmp(int(Time.curtime) + 1, Time.curtimestr) == 0)
        time.sleep(1.05)
        assert Time.cmp(time.time(), Time.curtime) == 1
        assert Time.cmp(Time.timetostring(time.time()), Time.curtimestr) == 1
DistributedCapturePoint.py 文件源码 项目:POTCO-PS 作者: ksmit799 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def set_hp(self, hp):
            if type(hp) in [
                types.IntType,
                types.FloatType]:
                self._DistributedCapturePoint__hp = hp
            else:
                self._DistributedCapturePoint__hp = 0
DistributedCapturePoint.py 文件源码 项目:POTCO-PS 作者: ksmit799 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def set_maxHp(self, maxHp):
            if type(maxHp) in [
                types.IntType,
                types.FloatType]:
                self._DistributedCapturePoint__maxHp = maxHp
            else:
                self._DistributedCapturePoint__maxHp = 1
DistributedBattleAvatar.py 文件源码 项目:POTCO-PS 作者: ksmit799 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def set_hp(self, hp):
            if type(hp) in [
                types.IntType,
                types.FloatType]:
                self._DistributedBattleAvatar__hp = hp
            else:
                self._DistributedBattleAvatar__hp = 0
DistributedBattleAvatar.py 文件源码 项目:POTCO-PS 作者: ksmit799 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def set_maxHp(self, maxHp):
            if type(maxHp) in [
                types.IntType,
                types.FloatType]:
                self._DistributedBattleAvatar__maxHp = maxHp
            else:
                self._DistributedBattleAvatar__maxHp = 1
DistributedInteractiveProp.py 文件源码 项目:POTCO-PS 作者: ksmit799 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def set_hp(self, hp):
            if type(hp) in [
                types.IntType,
                types.FloatType]:
                self._DistributedInteractiveProp__hp = hp
            else:
                self._DistributedInteractiveProp__hp = 1
common.py 文件源码 项目:pwtools 作者: elcorto 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def frepr(var, ffmt="%.16e"):
    """Similar to Python's repr(), but return floats formated with `ffmt` if
    `var` is a float.

    If `var` is a string, e.g. 'lala', it returns 'lala' not "'lala'" as
    Python's repr() does.

    Parameters
    ----------
    var : almost anything (str, None, int, float)
    ffmt : format specifier for float values

    Examples
    --------
    >>> frepr(1)
    '1'
    >>> frepr(1.0) 
    '1.000000000000000e+00' 
    >>> frepr(None)
    'None'
    >>> # Python's repr() does: 'abc' -> "'abc'"
    >>> frepr('abc')
    'abc' 
    """
    if isinstance(var, types.FloatType):
        return ffmt %var
    elif isinstance(var, types.StringType):
        return var
    else:
        return repr(var)
Elements.py 文件源码 项目:StuffShare 作者: StuffShare 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def AddRow( self, *cells ) :
        height = None
        if isinstance( cells[ 0 ], (IntType, FloatType, LongType) ):
            height = int( cells[ 0 ] )
            cells  = cells[ 1 : ]

        #  make sure all of the spans add up to the number of columns
        #  otherwise the table will get corrupted
        if self.ColumnCount != sum( [ cell.Span for cell in cells ] ) :
            raise Exception( 'ColumnCount != the total of this row\'s cell.Spans.' )

        self.Rows.append( ( height, cells ) )
qconf_object.py 文件源码 项目:config-api 作者: gridengine 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_float_key_map(cls, key_map):
        float_key_map = {}
        for (key,value) in key_map.items():
            if type(value) == types.FloatType:
                float_key_map[key] = value
        return float_key_map
Input.py 文件源码 项目:pymchelper 作者: DataMedSci 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def dump(self, pickler):
        pickler.dump(self.tag)
        pickler.dump(self._what)
        pickler.dump(self._extra)
        pickler.dump(self._comment)
        if self.prop:  # Skip system variables
            pickler.dump([x for x in self.prop.items()
                          if type(x[1]) in (IntType, LongType, FloatType, BooleanType, StringType, UnicodeType)])
        else:
            pickler.dump(None)
        pickler.dump(self.enable)

    # ----------------------------------------------------------------------
    # Load card from unpickler
    # ----------------------------------------------------------------------
unit.py 文件源码 项目:OpenRAM 作者: mguthaus 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _convert_to(l, dest_unit="m"):
    if type(l) in (types.IntType, types.LongType, types.FloatType):
        return l * _m[_default_unit] * scale['u'] / _m[dest_unit]
    elif not isinstance(l, length): 
        l = length(l)       # convert to length instance if necessary

    return (l.t + l.u*scale['u'] + l.v*scale['v'] + l.w*scale['w'] + l.x*scale['x']) / _m[dest_unit]
humannum.py 文件源码 项目:pykit 作者: baishancloud 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def humannum(data, unit=None, include=None, exclude=None):

    if isinstance(data, types.DictType):

        data = data.copy()

        keys = set(data.keys())
        if include is not None:
            keys = keys & set(include)

        if exclude is not None:
            keys = keys - set(exclude)

        for k in keys:
            data[k] = humannum(data[k])

        return data

    elif isinstance(data, types.BooleanType):
        # We have to deal with bool because for historical reason bool is
        # subclass of int.
        # When bool is introduced into python 2.2 it is represented with int,
        # similar to C.
        return data

    elif isinstance(data, types.ListType):
        return [humannum(x) for x in data]

    elif isinstance(data, types.StringTypes):
        return data

    elif isinstance(data, integer_types):
        return humannum_int(data, unit=unit)

    elif isinstance(data, types.FloatType):
        if data > 999:
            return humannum_int(int(data), unit=unit)
        elif abs(data) < 0.0000000001:
            return '0'
        else:
            return '%.2f' % (data)

    else:
        return data
reflect.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def objgrep(start, goal, eq=isLike, path='', paths=None, seen=None, showUnknowns=0, maxDepth=None):
    '''An insanely CPU-intensive process for finding stuff.
    '''
    if paths is None:
        paths = []
    if seen is None:
        seen = {}
    if eq(start, goal):
        paths.append(path)
    if seen.has_key(id(start)):
        if seen[id(start)] is start:
            return
    if maxDepth is not None:
        if maxDepth == 0:
            return
        maxDepth -= 1
    seen[id(start)] = start
    if isinstance(start, types.DictionaryType):
        r = []
        for k, v in start.items():
            objgrep(k, goal, eq, path+'{'+repr(v)+'}', paths, seen, showUnknowns, maxDepth)
            objgrep(v, goal, eq, path+'['+repr(k)+']', paths, seen, showUnknowns, maxDepth)
    elif isinstance(start, types.ListType) or isinstance(start, types.TupleType):
        for idx in xrange(len(start)):
            objgrep(start[idx], goal, eq, path+'['+str(idx)+']', paths, seen, showUnknowns, maxDepth)
    elif isinstance(start, types.MethodType):
        objgrep(start.im_self, goal, eq, path+'.im_self', paths, seen, showUnknowns, maxDepth)
        objgrep(start.im_func, goal, eq, path+'.im_func', paths, seen, showUnknowns, maxDepth)
        objgrep(start.im_class, goal, eq, path+'.im_class', paths, seen, showUnknowns, maxDepth)
    elif hasattr(start, '__dict__'):
        for k, v in start.__dict__.items():
            objgrep(v, goal, eq, path+'.'+k, paths, seen, showUnknowns, maxDepth)
        if isinstance(start, types.InstanceType):
            objgrep(start.__class__, goal, eq, path+'.__class__', paths, seen, showUnknowns, maxDepth)
    elif isinstance(start, weakref.ReferenceType):
        objgrep(start(), goal, eq, path+'()', paths, seen, showUnknowns, maxDepth)
    elif (isinstance(start, types.StringTypes+
                    (types.IntType, types.FunctionType,
                     types.BuiltinMethodType, RegexType, types.FloatType,
                     types.NoneType, types.FileType)) or
          type(start).__name__ in ('wrapper_descriptor', 'method_descriptor',
                                   'member_descriptor', 'getset_descriptor')):
        pass
    elif showUnknowns:
        print 'unknown type', type(start), start
    return paths
reflect.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def objgrep(start, goal, eq=isLike, path='', paths=None, seen=None, showUnknowns=0, maxDepth=None):
    '''An insanely CPU-intensive process for finding stuff.
    '''
    if paths is None:
        paths = []
    if seen is None:
        seen = {}
    if eq(start, goal):
        paths.append(path)
    if seen.has_key(id(start)):
        if seen[id(start)] is start:
            return
    if maxDepth is not None:
        if maxDepth == 0:
            return
        maxDepth -= 1
    seen[id(start)] = start
    if isinstance(start, types.DictionaryType):
        r = []
        for k, v in start.items():
            objgrep(k, goal, eq, path+'{'+repr(v)+'}', paths, seen, showUnknowns, maxDepth)
            objgrep(v, goal, eq, path+'['+repr(k)+']', paths, seen, showUnknowns, maxDepth)
    elif isinstance(start, types.ListType) or isinstance(start, types.TupleType):
        for idx in xrange(len(start)):
            objgrep(start[idx], goal, eq, path+'['+str(idx)+']', paths, seen, showUnknowns, maxDepth)
    elif isinstance(start, types.MethodType):
        objgrep(start.im_self, goal, eq, path+'.im_self', paths, seen, showUnknowns, maxDepth)
        objgrep(start.im_func, goal, eq, path+'.im_func', paths, seen, showUnknowns, maxDepth)
        objgrep(start.im_class, goal, eq, path+'.im_class', paths, seen, showUnknowns, maxDepth)
    elif hasattr(start, '__dict__'):
        for k, v in start.__dict__.items():
            objgrep(v, goal, eq, path+'.'+k, paths, seen, showUnknowns, maxDepth)
        if isinstance(start, types.InstanceType):
            objgrep(start.__class__, goal, eq, path+'.__class__', paths, seen, showUnknowns, maxDepth)
    elif isinstance(start, weakref.ReferenceType):
        objgrep(start(), goal, eq, path+'()', paths, seen, showUnknowns, maxDepth)
    elif (isinstance(start, types.StringTypes+
                    (types.IntType, types.FunctionType,
                     types.BuiltinMethodType, RegexType, types.FloatType,
                     types.NoneType, types.FileType)) or
          type(start).__name__ in ('wrapper_descriptor', 'method_descriptor',
                                   'member_descriptor', 'getset_descriptor')):
        pass
    elif showUnknowns:
        print 'unknown type', type(start), start
    return paths


问题


面经


文章

微信
公众号

扫码关注公众号