python类isinstance()的实例源码

dmClasses.py 文件源码 项目:CRDataManager 作者: NobahdiAtoll 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def FieldConvert(self, strValue, strField=None):
        if dmGlobals.TraceFunctionMessages: print 'Method: dmParameters:FieldConvert(stringValue, stringFieldName)'

        FieldValue = self.Field
        if strField != None:
            FieldValue = strField

        theVal = strValue
        try:
            if FieldValue in dmGlobals.ALLOWEDVALS:
                if FieldValue in dmGlobals.FIELDSLIST and not dmGlobals.IsList(strValue):
                    theVal = strValue.Split(Array[str](dmGlobals.CRLISTDELIMITER), StringSplitOptions.RemoveEmptyEntries)
                elif FieldValue in dmGlobals.FIELDSBOOL and not dmGlobals.IsBool(strValue):
                    theVal = dmGlobals.StringToBool(strValue)
                elif FieldValue in dmGlobals.FIELDSDATETIME and not dmGlobals.IsDateTime(strValue):
                    theVal = dmGlobals.StringToDate(strValue)
                elif FieldValue in dmGlobals.FIELDSNUMERIC and not dmGlobals.IsFloat(strValue):
                    theVal = dmGlobals.StringToFloat(strValue)
                elif FieldValue in dmGlobals.FIELDSMANGAYESNO and not dmGlobals.IsMangaYesNo(strValue):
                    theVal = dmGlobals.StringToMangaYesNo(strValue)
                elif FieldValue in dmGlobals.FIELDSYESNO and not dmGlobals.IsYesNo(strValue):
                    theVal = dmGlobals.StringToYesNo(strValue)
                elif FieldValue in dmGlobals.FIELDSPSUEDONUMERIC and not isinstance(strValue,str):
                    try:                    
                        theVal = strValue.ToString()
                    except:
                        pass
            #otherwise just return the value
        except Exception as ex:

            pass
        return theVal
misc.py 文件源码 项目:blackmamba 作者: zrzka 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def pow(x, y, z=_SENTINEL):
        """
        pow(x, y[, z]) -> number

        With two arguments, equivalent to x**y.  With three arguments,
        equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
        """
        # Handle newints
        if isinstance(x, newint):
            x = long(x)
        if isinstance(y, newint):
            y = long(y)
        if isinstance(z, newint):
            z = long(z)

        try:
            if z == _SENTINEL:
                return _builtin_pow(x, y)
            else:
                return _builtin_pow(x, y, z)
        except ValueError:
            if z == _SENTINEL:
                return _builtin_pow(x+0j, y)
            else:
                return _builtin_pow(x+0j, y, z)

    # ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
    #     callable = __builtin__.callable
misc.py 文件源码 项目:beepboop 作者: nicolehe 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def pow(x, y, z=_SENTINEL):
        """
        pow(x, y[, z]) -> number

        With two arguments, equivalent to x**y.  With three arguments,
        equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
        """
        # Handle newints
        if isinstance(x, newint):
            x = long(x)
        if isinstance(y, newint):
            y = long(y)
        if isinstance(z, newint):
            z = long(z)

        try:
            if z == _SENTINEL:
                return _builtin_pow(x, y)
            else:
                return _builtin_pow(x, y, z)
        except ValueError:
            if z == _SENTINEL:
                return _builtin_pow(x+0j, y)
            else:
                return _builtin_pow(x+0j, y, z)

    # ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
    #     callable = __builtin__.callable
compatibility.py 文件源码 项目:watcher 作者: nosmokingbandit 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def isinstance20(a, typea):
        if type(typea) != type(type):
            raise TypeError("TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types")
        return type(typea) != typea
compatibility.py 文件源码 项目:watcher 作者: nosmokingbandit 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def reversed(data):
            if not isinstance(data, list):
                data = list(data)
            return data[::-1]
compatibility.py 文件源码 项目:watcher 作者: nosmokingbandit 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def reversed(data):
            if not isinstance(data, list):
                data = list(data)
            reversed_data = []
            for index in xrange(len(data)-1, -1, -1):
                reversed_data.append(data[index])
            return reversed_data

# --- sorted() from Python 2.4 ---
misc.py 文件源码 项目:hackathon 作者: vertica 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def pow(x, y, z=_SENTINEL):
        """
        pow(x, y[, z]) -> number

        With two arguments, equivalent to x**y.  With three arguments,
        equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
        """
        # Handle newints
        if isinstance(x, newint):
            x = long(x)
        if isinstance(y, newint):
            y = long(y)
        if isinstance(z, newint):
            z = long(z)

        try:
            if z == _SENTINEL:
                return _builtin_pow(x, y)
            else:
                return _builtin_pow(x, y, z)
        except ValueError:
            if z == _SENTINEL:
                return _builtin_pow(x+0j, y)
            else:
                return _builtin_pow(x+0j, y, z)

    # ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
    #     callable = __builtin__.callable
misc.py 文件源码 项目:yatta_reader 作者: sound88 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def pow(x, y, z=_SENTINEL):
        """
        pow(x, y[, z]) -> number

        With two arguments, equivalent to x**y.  With three arguments,
        equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
        """
        # Handle newints
        if isinstance(x, newint):
            x = long(x)
        if isinstance(y, newint):
            y = long(y)
        if isinstance(z, newint):
            z = long(z)

        try:
            if z == _SENTINEL:
                return _builtin_pow(x, y)
            else:
                return _builtin_pow(x, y, z)
        except ValueError:
            if z == _SENTINEL:
                return _builtin_pow(x+0j, y)
            else:
                return _builtin_pow(x+0j, y, z)

    # ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
    #     callable = __builtin__.callable
dmClasses.py 文件源码 项目:CRDataManager 作者: NobahdiAtoll 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def SetFieldValue(self, book, newValue, strField=None):
        """Determines the proper write to book technique (Standard or Custom Field) and applies value"""
        if dmGlobals.TraceFunctionMessages: print 'Method: dmAction:SetValue(book, objNewValue, stringFieldName)'

        FieldValue = self.Field

        if strField != None:
            FieldValue = strField

        previousVal = self.GetFieldValue(book, FieldValue)

        newVal = newValue

        strReport = ''            
        if FieldValue in dmGlobals.FIELDSLIST:
            if dmGlobals.SortLists:
                newVal.sort()
            newVal = dmGlobals.CRLISTDELIMITER.join(newVal)
            previousVal = dmGlobals.CRLISTDELIMITER.join(previousVal)

        if FieldValue in dmGlobals.ALLOWEDVALS:
            try:
                if FieldValue in dmGlobals.FIELDSNUMERIC:
                    setattr(book, FieldValue, dmGlobals.StringToFloat(newVal)) #convert to float
                else:
                    setattr(book, FieldValue, newVal.ToString())
                #prepare the report
                strReport = '    Field: ' + FieldValue + '    Action: ' + self.ToString()
                strReport = strReport + System.Environment.NewLine + '        Previous Value: ' + dmGlobals.ToString(previousVal)
                strReport = strReport + System.Environment.NewLine + '        New Value: ' + dmGlobals.ToString(newVal) + '\r\n'
            except Exception as er:
                #report errors instead
                strReport = '    An unexpected error occured in Action: ' + self.ToString() + '    Parent Ruleset : ' + self.Parent.Name
                if isinstance(er, dmConversionError):
                    strReport = strReport + ' Error' + er.msg
                pass
        else:
            self.SetCustomField(book, FieldValue, newVal)
            #prepare the report
            if strReport != '': strReport = System.Environment.NewLine
            strReport = '    CustomField: ' + self.Field + '    Action: ' + self.ToString()
            strReport = strReport + System.Environment.NewLine + '        Previous Value: ' + dmGlobals.ToString(previousVal)
            strReport = strReport + System.Environment.NewLine + '        New Value: ' + dmGlobals.ToString(newVal)
        return strReport


问题


面经


文章

微信
公众号

扫码关注公众号