本文整理汇总了Python中repr.repr函数的典型用法代码示例。如果您正苦于以下问题:Python repr函数的具体用法?Python repr怎么用?Python repr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了repr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dwg_file_collector
def dwg_file_collector(bldgs_dict, location=os.getcwd()):
"""
...
Args:
bldgs_dict (func) = A call to the bldgs_dict function.
location (str) = A string representation of the directory location.
Returns:
dwg_bldg_code (dict) = A dictionary that contains a list of every dwg
per building folder.
dwg_bldg_number (dict) = A dictionary that contains a list of every dwg
per building folder.
in the subfolders.
Examples:
>>> dwg_file_collector(bldgs_dict('...\qryAllBldgs.xlsx'),
'...\CAD-to-esri-3D-Network\\floorplans')
Executing bldgs_dict...
CU Boulder buildings: {u'131': u'ATHN', u'133': u'TB33', ...}
Executing dwg_file_collector...
16 dwgs were found in: .../CAD-to-esri-3D-Network/floorplans/
Buildings numbers dictionary: {'338': ['S-338-01-DWG-BAS.dwg',...}
Buildings codes dictionary: {u'ADEN': ['S-339-01-DWG-BAS.dwg',...}
"""
# getting the name of the function programatically.
print ('Executing {}... '.format(inspect.currentframe().f_code.co_name))
original_workspace = os.getcwd()
# making the path compatible with python.
location = location.replace('\\', '/') + '/'
os.chdir(location)
folders = [p.replace('\\', '') for p in glob.glob('*/')]
# so the number of dwgs that were found can be reported.
dwg_files = []
dwg_bldg_number = {}
dwg_bldg_code = {}
for folder in folders:
folder_path = ''.join([location, folder])
os.chdir(folder_path)
folder_dwg_files = glob.glob('*.dwg')
# our current dwg naming convention is as follows:
# 'bldg_number-floor_number-DWG-drawing_type (i.e.'325-01-DWG-BAS.dwg')
# removes 'ROOF' files from the floorplans' list.
for i, dwg in enumerate(folder_dwg_files):
if dwg[-7:] == 'BAS.dwg' and 'ROOF' not in dwg:
folder_dwg_files[i] = '/'.join([folder_path, dwg])
else:
folder_dwg_files.remove(dwg)
# dict where the buildings' numbers are the keys.
dwg_bldg_number[folder] = folder_dwg_files
# dict where the buildings' codes are the keys.
dwg_bldg_code[bldgs_dict[folder]] = folder_dwg_files
dwg_files += folder_dwg_files
os.chdir(original_workspace)
print ('{} dwgs were found in: {} '.format(
(len(dwg_files)), location))
print('Buildings numbers dictionary: {}'.format(
reprlib.repr(dwg_bldg_number)))
print('Buildings codes dictionary: {}'.format(
reprlib.repr(dwg_bldg_code)))
return dwg_bldg_number, dwg_bldg_code
示例2: format_stack_entry
def format_stack_entry(self, frame_lineno, lprefix=': '):
import repr
frame, lineno = frame_lineno
filename = canonic(frame.f_code.co_filename)
s = '%s(%r)' % (filename, lineno)
if frame.f_code.co_name:
s += frame.f_code.co_name
else:
s += "<lambda>"
locals = self.get_locals(frame)
if '__args__' in locals:
args = locals['__args__']
else:
args = None
if args:
s += repr.repr(args)
else:
s += '()'
if '__return__' in locals:
rv = locals['__return__']
s += '->'
s += repr.repr(rv)
line = linecache.getline(filename, lineno)
if line:
s += lprefix + line.strip()
return s
示例3: _dorequest
def _dorequest(self, rf, wf):
rp = pickle.Unpickler(rf)
try:
request = rp.load()
except EOFError:
return 0
if self._verbose > 1: print "Got request: %s" % repr(request)
try:
methodname, args, id = request
if '.' in methodname:
reply = (None, self._special(methodname, args), id)
elif methodname[0] == '_':
raise NameError, "illegal method name %s" % repr(methodname)
else:
method = getattr(self, methodname)
reply = (None, apply(method, args), id)
except:
reply = (sys.exc_type, sys.exc_value, id)
if id < 0 and reply[:2] == (None, None):
if self._verbose > 1: print "Suppress reply"
return 1
if self._verbose > 1: print "Send reply: %s" % repr(reply)
wp = pickle.Pickler(wf)
wp.dump(reply)
return 1
示例4: format_stack_entry
def format_stack_entry(self, frame_lineno, lprefix=': '):
import linecache, repr
frame, lineno = frame_lineno
filename = self.pdb.canonic(frame.f_code.co_filename)
L = [filename, lineno]
if frame.f_code.co_name:
L.append(frame.f_code.co_name)
else:
L.append("<lambda>")
if '__args__' in frame.f_locals:
L.append(repr.repr(frame.f_locals['__args__']))
else:
L.append([])
if '__return__' in frame.f_locals:
rv = frame.f_locals['__return__']
L.append(repr.repr(rv))
else:
L.append(None)
line = linecache.getline(filename, lineno)
if line:
L.append(line.strip())
else:
L.append('')
L.append(self.format_namespace(frame.f_locals))
L.append(self.format_namespace(frame.f_globals))
return L
示例5: format_stack_entry
def format_stack_entry(self, frame_lineno, lprefix=": "):
import linecache, repr
frame, lineno = frame_lineno
filename = self.canonic(frame.f_code.co_filename)
s = "%s(%r)" % (filename, lineno)
if frame.f_code.co_name:
s = s + frame.f_code.co_name
else:
s = s + "<lambda>"
if "__args__" in frame.f_locals:
args = frame.f_locals["__args__"]
else:
args = None
if args:
s = s + repr.repr(args)
else:
s = s + "()"
if "__return__" in frame.f_locals:
rv = frame.f_locals["__return__"]
s = s + "->"
s = s + repr.repr(rv)
line = linecache.getline(filename, lineno)
if line:
s = s + lprefix + line.strip()
return s
示例6: format_stack_entry
def format_stack_entry(self, frame_lineno, lprefix = ': '):
import linecache, repr
frame, lineno = frame_lineno
filename = self.canonic(frame.f_code.co_filename)
s = '%s(%r)' % (filename, lineno)
if frame.f_code.co_name:
s = s + frame.f_code.co_name
else:
s = s + '<lambda>'
if '__args__' in frame.f_locals:
args = frame.f_locals['__args__']
else:
args = None
if args:
s = s + repr.repr(args)
else:
s = s + '()'
if '__return__' in frame.f_locals:
rv = frame.f_locals['__return__']
s = s + '->'
s = s + repr.repr(rv)
line = linecache.getline(filename, lineno, frame.f_globals)
if line:
s = s + lprefix + line.strip()
return s
示例7: format_stack_entry
def format_stack_entry(self, frame_lineno, lprefix=': '):
import linecache, repr
frame, lineno = frame_lineno
filename = self.canonic(frame.f_code.co_filename)
## doctest hack
if filename.startswith('<doctest'):
lineno = frame.f_back.f_locals['example'].lineno + frame.f_back.f_locals['test'].lineno + 1
filename = frame.f_back.f_locals['test'].filename
s = 'doctest @ %s(%r)' % (filename, lineno)
else:
s = '%s(%r)' % (filename, lineno)
if frame.f_code.co_name:
s = s + frame.f_code.co_name
else:
s = s + "<lambda>"
if '__args__' in frame.f_locals:
args = frame.f_locals['__args__']
else:
args = None
if args:
s = s + repr.repr(args)
else:
s = s + '()'
if '__return__' in frame.f_locals:
rv = frame.f_locals['__return__']
s = s + '->'
s = s + repr.repr(rv)
line = linecache.getline(filename, lineno)
if line: s = s + lprefix + line.strip()
return s
示例8: format_stack_entry
def format_stack_entry(self, frame_lineno, prefix=""):
import linecache, repr, string
frame, lineno = frame_lineno
filename = frame.f_code.co_filename
s = ' at ' + filename + ':' + `lineno`
if frame.f_code.co_name:
f = frame.f_code.co_name
else:
f = "<lambda>"
if frame.f_locals.has_key('__args__'):
args = frame.f_locals['__args__']
else:
args = None
if args:
a = '(' + repr.repr(args) + ')'
else:
a = '()'
first_line = prefix + f + a + s + '\n'
# Don't want the ?() at <string>: line printed out; confuses ddd
if first_line[:15] == '?() at <string>':
return 'Issue "continue" command'
second_line = `lineno` + ' '
line = linecache.getline(filename, lineno)
if line: second_line = second_line + string.strip(line)
result = first_line + second_line
if frame.f_locals.has_key('__return__'):
rv = frame.f_locals['__return__']
third_line = 'Value returned is $1 = ' + repr.repr(rv)
result = result + '\n' + third_line
return result
示例9: format_stack_entry
def format_stack_entry(self, frame_lineno, lprefix=': '):
import linecache, repr
frame, lineno = frame_lineno
b_cls = '<module>';
if 'self' in frame.f_locals:
b_cls = frame.f_locals['self'].__class__.__name__
elif 'cls' in frame.f_locals:
b_cls = frame.f_locals['cls'].__name__
filename = self.canonic(frame.f_code.co_filename)
s = '%s(%r) %s:' % (filename, lineno, b_cls)
if frame.f_code.co_name:
s = s + frame.f_code.co_name
else:
s = s + "<lambda>"
if '__args__' in frame.f_locals:
args = frame.f_locals['__args__']
else:
args = None
if args:
s = s + repr.repr(args)
else:
s = s + '()'
if '__return__' in frame.f_locals:
rv = frame.f_locals['__return__']
s = s + '->'
s = s + repr.repr(rv)
line = linecache.getline(filename, lineno, frame.f_globals)
if line: s = s + lprefix + line.strip()
return s
示例10: draw
def draw(self, detail):
import linecache, codehack, string
d = self.win.begindrawing()
try:
h, v = 0, 0
for f, lineno in self.stack:
fn = f.f_code.co_filename
if f is self.curframe:
s = '> '
else:
s = ' '
s = s + fn + '(' + `lineno` + ')'
s = s + codehack.getcodename(f.f_code)
if f.f_locals.has_key('__args__'):
args = f.f_locals['__args__']
if args is not None:
s = s + repr.repr(args)
if f.f_locals.has_key('__return__'):
rv = f.f_locals['__return__']
s = s + '->'
s = s + repr.repr(rv)
line = linecache.getline(fn, lineno)
if line: s = s + ': ' + string.strip(line)
d.text((h, v), s)
v = v + d.lineheight()
finally:
d.close()
示例11: format_stack_entry
def format_stack_entry(self, frame_lineno, lprefix=": ", context=3):
import linecache, repr
ret = []
Colors = self.color_scheme_table.active_colors
ColorsNormal = Colors.Normal
tpl_link = "%s%%s%s" % (Colors.filenameEm, ColorsNormal)
tpl_call = "%s%%s%s%%s%s" % (Colors.vName, Colors.valEm, ColorsNormal)
tpl_line = "%%s%s%%s %s%%s" % (Colors.lineno, ColorsNormal)
tpl_line_em = "%%s%s%%s %s%%s%s" % (Colors.linenoEm, Colors.line, ColorsNormal)
frame, lineno = frame_lineno
return_value = ""
if "__return__" in frame.f_locals:
rv = frame.f_locals["__return__"]
# return_value += '->'
return_value += repr.repr(rv) + "\n"
ret.append(return_value)
# s = filename + '(' + `lineno` + ')'
filename = self.canonic(frame.f_code.co_filename)
link = tpl_link % filename
if frame.f_code.co_name:
func = frame.f_code.co_name
else:
func = "<lambda>"
call = ""
if func != "?":
if "__args__" in frame.f_locals:
args = repr.repr(frame.f_locals["__args__"])
else:
args = "()"
call = tpl_call % (func, args)
# The level info should be generated in the same format pdb uses, to
# avoid breaking the pdbtrack functionality of python-mode in *emacs.
if frame is self.curframe:
ret.append("> ")
else:
ret.append(" ")
ret.append("%s(%s)%s\n" % (link, lineno, call))
start = lineno - 1 - context // 2
lines = linecache.getlines(filename)
start = max(start, 0)
start = min(start, len(lines) - context)
lines = lines[start : start + context]
for i, line in enumerate(lines):
show_arrow = start + 1 + i == lineno
linetpl = (frame is self.curframe or show_arrow) and tpl_line_em or tpl_line
ret.append(self.__format_line(linetpl, filename, start + 1 + i, line, arrow=show_arrow))
return "".join(ret)
示例12: __call__
def __call__(self, test):
old = self.old or test.init_old(test.cloned_library)
legacy = self.legacy or test.init_legacy(test.cloned_library)
oldres = getattr(old, self.func_name)(*self.args, **self.kwargs)
newres = getattr(legacy, self.func_name)(*self.args, **self.kwargs)
test.assertEqual(oldres, newres, 'Equivalence test for %s with args: %s and kwargs: %s failed' % (
self.func_name, repr(self.args), repr(self.kwargs)))
self.retval = newres
return newres
示例13: format_stack_entry
def format_stack_entry(self, frame_lineno, lprefix=': ', context=3):
import linecache, repr
ret = ""
Colors = self.color_scheme_table.active_colors
ColorsNormal = Colors.Normal
tpl_link = '%s%%s%s' % (Colors.filenameEm, ColorsNormal)
tpl_call = 'in %s%%s%s%%s%s' % (Colors.vName, Colors.valEm, ColorsNormal)
tpl_line = '%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal)
tpl_line_em = '%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line,
ColorsNormal)
frame, lineno = frame_lineno
return_value = ''
if '__return__' in frame.f_locals:
rv = frame.f_locals['__return__']
#return_value += '->'
return_value += repr.repr(rv) + '\n'
ret += return_value
#s = filename + '(' + `lineno` + ')'
filename = self.canonic(frame.f_code.co_filename)
link = tpl_link % filename
if frame.f_code.co_name:
func = frame.f_code.co_name
else:
func = "<lambda>"
call = ''
if func != '?':
if '__args__' in frame.f_locals:
args = repr.repr(frame.f_locals['__args__'])
else:
args = '()'
call = tpl_call % (func, args)
level = '%s %s\n' % (link, call)
ret += level
start = lineno - 1 - context//2
lines = linecache.getlines(filename)
start = max(start, 0)
start = min(start, len(lines) - context)
lines = lines[start : start + context]
for i in range(len(lines)):
line = lines[i]
if start + 1 + i == lineno:
ret += self.__format_line(tpl_line_em, filename, start + 1 + i, line, arrow = True)
else:
ret += self.__format_line(tpl_line, filename, start + 1 + i, line, arrow = False)
return ret
示例14: _serve
def _serve(self):
if self._verbose: print "Wait for connection ..."
conn, address = self._socket.accept()
if self._verbose: print "Accepted connection from %s" % repr(address)
if not self._verify(conn, address):
print "*** Connection from %s refused" % repr(address)
conn.close()
return
rf = conn.makefile('r')
wf = conn.makefile('w')
ok = 1
while ok:
wf.flush()
if self._verbose > 1: print "Wait for next request ..."
ok = self._dorequest(rf, wf)
示例15: test
def test():
helper.dividing_with_title(' start ')
# repr
import repr
print repr.repr(set('abcdedabc'))
print repr.repr(dict({'name' : 'wjh', 'age' : 11}))
# pprint
import pprint
t = [[[['black', 'cyan'], 'white', ['green', 'red']], [['magenta', 'yellow'], 'blue']]]
pprint.pprint(t,None,1,80)
# textwrap
import textwrap
doc = """The wrap() method is just like fill() except that it returns
a list of strings instead of one big string with newlines to separate
the wrapped lines."""
print textwrap.fill(doc,50)
# locale
import locale
locale.setlocale(locale.LC_ALL,'English_United States.1252')
conv=locale.localeconv()
x = 1234.6
print locale.format("%d", x, grouping=True)
print locale.format_string("%s%.*f", (conv['currency_symbol'], conv['frac_digits'], x), grouping=True)
# Template
from string import Template
t = Template('${village}folk send $$10 to $cause.')
print t.substitute(village='Nottingham', cause='the ditch fund')
d = dict(name='wjh',age=20)
t = Template('name: $name and age: $age')
print t.substitute(d)
print t.safe_substitute(d)
import time, os.path
photofiles = ['img_1074.jpg', 'img_1076.jpg', 'img_1077.jpg']
# fmt = raw_input('Enter rename style (%d-date %n-seqnum %f-format): ')
# print fmt
# struct
import struct
data = open(helper.getfile('test.txt'), 'rb')
print data.readline()
data.close()