Python string.ljust() Examples
The following are 17
code examples of string.ljust().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
string
, or try the search function
.
Example #1
Source File: nmb.py From cracke-dit with MIT License | 6 votes |
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()
Example #2
Source File: XpmImagePlugin.py From keras-lambda with MIT License | 6 votes |
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
Example #3
Source File: nmb.py From PiBunny with MIT License | 6 votes |
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()
Example #4
Source File: utils.py From xunfengES with GNU General Public License v3.0 | 6 votes |
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'
Example #5
Source File: utils.py From xunfengES with GNU General Public License v3.0 | 6 votes |
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'
Example #6
Source File: utils.py From pelisalacarta-ce with GNU General Public License v3.0 | 6 votes |
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'
Example #7
Source File: XpmImagePlugin.py From CNCGToolKit with MIT License | 6 votes |
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
Example #8
Source File: utils.py From addon with GNU General Public License v3.0 | 6 votes |
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'
Example #9
Source File: XpmImagePlugin.py From mxnet-lambda with Apache License 2.0 | 6 votes |
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
Example #10
Source File: nmb.py From tvalacarta with GNU General Public License v3.0 | 6 votes |
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()
Example #11
Source File: nmb.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
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()
Example #12
Source File: models.py From django-wham with MIT License | 5 votes |
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
Example #13
Source File: CListItem.py From filmkodi with Apache License 2.0 | 5 votes |
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
Example #14
Source File: recipe-52194.py From code with MIT License | 5 votes |
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
Example #15
Source File: recipe-52192.py From code with MIT License | 5 votes |
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
Example #16
Source File: FeatureDumper.py From Ossian with Apache License 2.0 | 4 votes |
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).
Example #17
Source File: structures.py From BioBlender with BSD 2-Clause "Simplified" License | 4 votes |
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