本文整理汇总了Python中mx.Tools.trange方法的典型用法代码示例。如果您正苦于以下问题:Python Tools.trange方法的具体用法?Python Tools.trange怎么用?Python Tools.trange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mx.Tools
的用法示例。
在下文中一共展示了Tools.trange方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: search_bench
# 需要导入模块: from mx import Tools [as 别名]
# 或者: from mx.Tools import trange [as 别名]
def search_bench(word, text):
iterations = Tools.trange(COUNT)
print ('Searching for all occurences of %r using ...' % word)
t0 = time.time()
so = TextTools.TextSearch(word)
for i in iterations:
l = so.findall(text)
t1 = time.time()
count = len(l)
print (' - mx.TextSearch.TextSearch().findall(): %5.3f ms (%i)' %
((t1 - t0) / COUNT * 1000.0, count))
t0 = time.time()
so = re.compile(word)
for i in iterations:
l = so.findall(text)
t1 = time.time()
count = len(l)
print (' - re.compile().findall(): %5.3f ms (%i)' %
((t1 - t0) / COUNT * 1000.0, count))
t0 = time.time()
for i in iterations:
count = text.count(word)
t1 = time.time()
print (' - text.count(): %5.3f ms (%i)' %
((t1 - t0) / COUNT * 1000.0, count))
示例2: feed_dict
# 需要导入模块: from mx import Tools [as 别名]
# 或者: from mx.Tools import trange [as 别名]
def feed_dict(self,table,rows=None):
""" Feeds a table (dict of lists) which is converted
to CSV.
Only the keys set as column names are used to form the CSV
data.
All lists in the dictionary must have equal length or at
least rows number of entries, if rows is given. None
entries are converted to empty strings, all other objects
are stringified.
"""
columns = self.columns
if not columns:
raise Error,'no output columns set'
rowlen = len(columns)
# Create an emtpy table
if not rows:
rows = 0
for column in columns:
nrows = len(table[column])
if nrows > rows:
rows = nrows
rowindices = Tools.trange(rows)
t = [None] * rows
for i in rowindices:
t[i] = [None] * rowlen
# Fill the table
for j,k in Tools.irange(columns):
for i in rowindices:
t[i][j] = table[k][i]
# Quote and join lines
t = [self.separator.join(self._quote(x)) for x in t]
# Add final CRLF and store CSV text
t.append('')
self.text = self.text + self.lineend.join(t)
示例3: print_sequence
# 需要导入模块: from mx import Tools [as 别名]
# 或者: from mx.Tools import trange [as 别名]
def print_sequence(obj,file=_sys.stdout,indent='',levels=2,
nonrecursive=()):
l = []
unfold = 0
try:
length = len(obj)
except (AttributeError, ValueError, TypeError):
return
for i in Tools.trange(min(length,_VALUE_LEN_LIMIT)):
try:
value = obj[i]
except:
break
try:
r = repr(value)
except:
r = '*repr()-error*'
# Truncate
if len(r) > _VALUE_LEN_LIMIT:
r = r[:_VALUE_LEN_LIMIT] + '...'
# Write value
l.append((value,r))
# Only unfold sequences that have non-string items or string items
# with more than on character
if not is_string(value) or len(value) > 1:
unfold = 1
if len(obj) > _VALUE_LEN_LIMIT:
l.append(('...','...truncated...'))
# Unfold value object
if unfold:
for i,(value,rvalue) in irange(l):
file.write('%s%-15s = %s\n' % (indent, '[%i]' % i, rvalue))
if levels > 1:
print_recursive(value,file,indent + ' ',levels-1,
nonrecursive=nonrecursive)
示例4: feed_objects
# 需要导入模块: from mx import Tools [as 别名]
# 或者: from mx.Tools import trange [as 别名]
def feed_objects(self,objects,
getattr=getattr):
""" Feeds a sequence of objects which is converted to CSV.
For each object the set column names are interpreted as
object attributes and used as basis for the CSV data.
None values are converted to empty strings, all other
attributes are added stringified.
"""
columns = self.columns
if not columns:
raise Error,'no output columns set'
rowlen = len(columns)
# Create an emtpy table
rows = len(objects)
rowindices = Tools.trange(rows)
t = [None] * rows
for i in rowindices:
t[i] = [None] * rowlen
# Fill the table
icols = Tools.irange(columns)
for i in rowindices:
obj = objects[i]
for j,name in icols:
t[i][j] = str(getattr(obj, name))
# Quote and join lines
t = [self.separator.join(self._quote(x)) for x in t]
# Add final CRLF and store CSV text
t.append('')
self.text = self.text + self.lineend.join(t)