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


Python string.ljust方法代码示例

本文整理汇总了Python中string.ljust方法的典型用法代码示例。如果您正苦于以下问题:Python string.ljust方法的具体用法?Python string.ljust怎么用?Python string.ljust使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在string的用法示例。


在下文中一共展示了string.ljust方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: encode_name

# 需要导入模块: import string [as 别名]
# 或者: from string import ljust [as 别名]
def encode_name(name, type, scope):
    if name == '*':
        name += '\0' * 15
    elif len(name) > 15:
        name = name[:15] + chr(type)
    else:
        name = string.ljust(name, 15) + chr(type)

    encoded_name = chr(len(name) * 2) + re.sub('.', _do_first_level_encoding, name)
    if scope:
        encoded_scope = ''
        for s in string.split(scope, '.'):
            encoded_scope = encoded_scope + chr(len(s)) + s
        return encoded_name + encoded_scope + '\0'
    else:
        return encoded_name.encode('ascii') + '\0'

# Internal method for use in encode_name() 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:20,代码来源:nmb.py

示例2: encode_name

# 需要导入模块: import string [as 别名]
# 或者: from string import ljust [as 别名]
def encode_name(name, type, scope):
    if name == '*':
        name = name + '\0' * 15
    elif len(name) > 15:
        name = name[:15] + chr(type)
    else:
        name = string.ljust(name, 15) + chr(type)
        
    encoded_name = chr(len(name) * 2) + re.sub('.', _do_first_level_encoding, name)
    if scope:
        encoded_scope = ''
        for s in string.split(scope, '.'):
            encoded_scope = encoded_scope + chr(len(s)) + s
        return encoded_name + encoded_scope + '\0'
    else:
        return encoded_name + '\0'

# Internal method for use in encode_name() 
开发者ID:tvalacarta,项目名称:tvalacarta,代码行数:20,代码来源:nmb.py

示例3: load_read

# 需要导入模块: import string [as 别名]
# 或者: from string import ljust [as 别名]
def load_read(self, bytes):

        #
        # load all image data in one chunk

        xsize, ysize = self.size

        s = [None] * ysize

        for i in range(ysize):
            s[i] = string.ljust(self.fp.readline()[1:xsize+1], xsize)

        self.fp = None

        return string.join(s, "")

#
# Registry 
开发者ID:awslabs,项目名称:mxnet-lambda,代码行数:20,代码来源:XpmImagePlugin.py

示例4: encode_name

# 需要导入模块: import string [as 别名]
# 或者: from string import ljust [as 别名]
def encode_name(name, type, scope = None):
    """
    Perform first and second level encoding of name as specified in RFC 1001 (Section 4)
    """
    if name == '*':
        name = name + '\0' * 15
    elif len(name) > 15:
        name = name[:15] + chr(type)
    else:
        name = string.ljust(name, 15) + chr(type)

    def _do_first_level_encoding(m):
        s = ord(m.group(0))
        return string.uppercase[s >> 4] + string.uppercase[s & 0x0f]

    encoded_name = chr(len(name) * 2) + re.sub('.', _do_first_level_encoding, name)
    if scope:
        encoded_scope = ''
        for s in string.split(scope, '.'):
            encoded_scope = encoded_scope + chr(len(s)) + s
        return encoded_name + encoded_scope + '\0'
    else:
        return encoded_name + '\0' 
开发者ID:alfa-addon,项目名称:addon,代码行数:25,代码来源:utils.py

示例5: __str__

# 需要导入模块: import string [as 别名]
# 或者: from string import ljust [as 别名]
def __str__(self):
    classStr = ''
    for name, value in self.__class__.__dict__.items( ) + self.__dict__.items( ): 
        classStr += string.ljust( name, 15 ) + '\t' + str( value ) + '\n'
    return classStr 
开发者ID:ActiveState,项目名称:code,代码行数:7,代码来源:recipe-52192.py

示例6: docs

# 需要导入模块: import string [as 别名]
# 或者: from string import ljust [as 别名]
def docs(self):
        s = ''
        s += '\n  ' + string.ljust('Field', 30) + string.ljust('Type', 10)
        s += '\n----------------------------------------------------------------'
        for field in self.get_fields():
            prefix = '⚷ ' if field.primary_key else '  '
            s += '\n' + prefix + string.ljust(field.name, 30) + string.ljust(field.type_repr, 10)
        return s 
开发者ID:mbylstra,项目名称:django-wham,代码行数:10,代码来源:models.py

示例7: __str__

# 需要导入模块: import string [as 别名]
# 或者: from string import ljust [as 别名]
def __str__(self):
        txt = ''
        for key in self.infos.keys():
            txt += str(string.ljust(key, 15)) + ':\t' + str(self[key]) + '\n'
        return txt




# STATIC FUNCTIONS 
开发者ID:mrknow,项目名称:filmkodi,代码行数:12,代码来源:CListItem.py

示例8: process_utterance

# 需要导入模块: import string [as 别名]
# 或者: from string import ljust [as 别名]
def process_utterance(self, utt, make_label=True):

        utt_data = []        
        utt_questions = defaultdict(int) 

        nodelist = utt.xpath(self.config["target_nodes"])
        if nodelist == []:            
            print('WARNING: FeatureDumper\'s target_nodes matches no nodes: %s'%(self.config["target_nodes"]))

        for node in nodelist:
            
            self.htk_state_xpath = None ## make sure this is none.
            self.start_time_xpath = None
            self.end_time_xpath = None

                
            ## for phone!:--          
            node_data, node_questions = self.get_node_context_label(node)
            
            statelist = node.xpath('.//'+self.state_tag)
            assert statelist != []
            for (i, state) in enumerate(statelist):
            
                state_ix = i + 2
                state_node_data = "%s[%s]"%(node_data, state_ix)
            
                
                start_time = state.attrib.get(self.start_attribute, '_NA_')  ## no time at runtime!
                end_time = state.attrib.get(self.end_attribute, '_NA_')

                if not (start_time=="_NA_" or end_time=="_NA_"):

                    start_time = string.ljust(str(ms_to_htk(start_time)), 10)
                    end_time = string.ljust(str(ms_to_htk(end_time)), 10)

                    state_node_data = "%s %s %s"%(start_time, end_time, state_node_data)     
                
                utt_data.append(state_node_data)
                
            ##utt_questions.update(node_questions)
            ## Sum the dictionaries' values:
            for question in node_questions:
                utt_questions[question]+=node_questions[question]
                       
        if make_label:
            label_file = utt.get_filename(self.config["output_filetype"])
            writelist(utt_data, label_file, uni=True)


        return (utt_data, utt_questions) ## for writing utterance-level labels,
                ## these returned values will be ignored. But these can be used to
                ## acccumulate questions and features over the whole corpus for  
                ## training (see train() method). 
开发者ID:CSTR-Edinburgh,项目名称:Ossian,代码行数:55,代码来源:FeatureDumper.py

示例9: __str__

# 需要导入模块: import string [as 别名]
# 或者: from string import ljust [as 别名]
def __str__(self):
        """
            Returns a string of the new atom type.  Uses the ATOM string
            output but changes the first field to either by ATOM or
            HETATM as necessary.

            Returns
                str: String with ATOM/HETATM field set appropriately
        """
        str = ""
        tstr = self.type
        str = str + string.ljust(tstr, 6)[:6]
        tstr = "%d" % self.serial
        str = str + string.rjust(tstr, 5)[:5]
        str = str + " "
        tstr = self.name
        if len(tstr) == 4 or len(tstr.strip("FLIP")) == 4:
            str = str + string.ljust(tstr, 4)[:4]
        else:
            str = str + " " + string.ljust(tstr, 3)[:3]

        tstr = self.resName
        if len(tstr) == 4:
            str = str + string.ljust(tstr, 4)[:4]
        else:
            str = str + " " + string.ljust(tstr, 3)[:3]
            
        str = str + " "
        tstr = self.chainID
        str = str + string.ljust(tstr, 1)[:1]
        tstr = "%d" % self.resSeq
        str = str + string.rjust(tstr, 4)[:4]
        if self.iCode != "":
            str = str + "%s   " % self.iCode
        else:
            str = str + "    "
        tstr = "%8.3f" % self.x
        str = str + string.ljust(tstr, 8)[:8]
        tstr = "%8.3f" % self.y
        str = str + string.ljust(tstr, 8)[:8]
        tstr = "%8.3f" % self.z
        str = str + string.ljust(tstr, 8)[:8]
        if self.ffcharge != None: ffcharge = "%.4f" % self.ffcharge
        else: ffcharge = "0.0000"
        str = str + string.rjust(ffcharge, 8)[:8]
        if self.radius != None: ffradius = "%.4f" % self.radius
        else: ffradius = "0.0000"
        str = str + string.rjust(ffradius, 7)[:7]
        return str 
开发者ID:MonZop,项目名称:BioBlender,代码行数:51,代码来源:structures.py


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