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


Python repr.repr函数代码示例

本文整理汇总了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
开发者ID:ulisessol7,项目名称:CAD-to-esri-3D-Network,代码行数:60,代码来源:CADtoesri3DNetwork.py

示例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
开发者ID:MarcoYuu,项目名称:dotfiles,代码行数:26,代码来源:bdb.py

示例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
开发者ID:asottile,项目名称:ancient-pythons,代码行数:25,代码来源:server.py

示例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
开发者ID:BackupTheBerlios,项目名称:pida-svn,代码行数:26,代码来源:debugger.py

示例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
开发者ID:krattai,项目名称:xbmc-antiquated,代码行数:26,代码来源:bdb.py

示例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
开发者ID:webiumsk,项目名称:WOT-0.9.15-CT,代码行数:25,代码来源:bdb.py

示例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
开发者ID:hexsprite,项目名称:doctestpdbhacks,代码行数:33,代码来源:__init__.py

示例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
开发者ID:aidanfarrow,项目名称:GC_tidy,代码行数:30,代码来源:pydb.py

示例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
开发者ID:proper337,项目名称:dotfiles,代码行数:29,代码来源:bdb.py

示例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()
开发者ID:asottile,项目名称:ancient-pythons,代码行数:27,代码来源:wdb.py

示例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)
开发者ID:CVL-dev,项目名称:StructuralBiology,代码行数:58,代码来源:Debugger.py

示例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
开发者ID:ards,项目名称:calibre,代码行数:9,代码来源:legacy.py

示例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
开发者ID:simonpercivall,项目名称:tbtools,代码行数:56,代码来源:Debugger.py

示例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)
开发者ID:asottile,项目名称:ancient-pythons,代码行数:15,代码来源:server.py

示例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()
开发者ID:jinghewang,项目名称:purepython,代码行数:48,代码来源:other11.py


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