當前位置: 首頁>>代碼示例>>Python>>正文


Python strop.maketrans方法代碼示例

本文整理匯總了Python中strop.maketrans方法的典型用法代碼示例。如果您正苦於以下問題:Python strop.maketrans方法的具體用法?Python strop.maketrans怎麽用?Python strop.maketrans使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在strop的用法示例。


在下文中一共展示了strop.maketrans方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: maketrans

# 需要導入模塊: import strop [as 別名]
# 或者: from strop import maketrans [as 別名]
def maketrans(fromstr, tostr):
    """maketrans(frm, to) -> string

    Return a translation table (a string of 256 bytes long)
    suitable for use in string.translate.  The strings frm and to
    must be of the same length.

    """
    if len(fromstr) != len(tostr):
        raise ValueError, "maketrans arguments must have same length"
    global _idmapL
    if not _idmapL:
        _idmapL = map(None, _idmap)
    L = _idmapL[:]
    fromstr = map(ord, fromstr)
    for i in range(len(fromstr)):
        L[fromstr[i]] = tostr[i]
    return ''.join(L)



#################################################################### 
開發者ID:linuxscout,項目名稱:mishkal,代碼行數:24,代碼來源:string24.py

示例2: maketrans

# 需要導入模塊: import strop [as 別名]
# 或者: from strop import maketrans [as 別名]
def maketrans(fromstr, tostr):
    """maketrans(frm, to) -> string

    Return a translation table (a string of 256 bytes long)
    suitable for use in string.translate.  The strings frm and to
    must be of the same length.

    """
    if len(fromstr) != len(tostr):
        raise ValueError, "maketrans arguments must have same length"
    global _idmapL
    if not _idmapL:
        _idmapL = list(_idmap)
    L = _idmapL[:]
    fromstr = map(ord, fromstr)
    for i in range(len(fromstr)):
        L[fromstr[i]] = tostr[i]
    return ''.join(L)



#################################################################### 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:24,代碼來源:string.py

示例3: maketrans

# 需要導入模塊: import strop [as 別名]
# 或者: from strop import maketrans [as 別名]
def maketrans(fromstr, tostr):
    """maketrans(frm, to) -> string

    Return a translation table (a string of 256 bytes long)
    suitable for use in string.translate.  The strings frm and to
    must be of the same length.

    """
    if len(fromstr) != len(tostr):
        raise ValueError, "maketrans arguments must have same length"
    global _idmapL
    if not _idmapL:
        _idmapL = list(_idmap)
    L = _idmapL[:]
    fromstr = map(ord, fromstr)
    for i in range(len(fromstr)):
        L[fromstr[i]] = tostr[i]
    return join(L, "")

# Substring replacement (global) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:22,代碼來源:stringold.py

示例4: test_maketrans

# 需要導入模塊: import strop [as 別名]
# 或者: from strop import maketrans [as 別名]
def test_maketrans(self):
        self.assertTrue(strop.maketrans("abc", "xyz") == transtable)
        self.assertRaises(ValueError, strop.maketrans, "abc", "xyzq") 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:5,代碼來源:test_strop.py


注:本文中的strop.maketrans方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。