2016-01-29 72 views
-2

我希望在开发过程中能够直接导航到Python源代码。PyCharm导航到Python源代码

例如,如果我在我的项目Foo.Bar()的某个方法上按F4将我带到类Foo中的function def __init__(self),PyCharm将打开该模块并将我置于定义该方法的行上。但是,当我按下F4,以string.format(fmt_str)我想采取

class Formatter: 
    def format(*args, **kwargs): 
     if not args: 
      raise TypeError("descriptor 'format' of 'Formatter' object " 
          "needs an argument") 
     self, *args = args # allow the "self" keyword be passed 
     try: 
      format_string, *args = args # allow the "format_string" keyword be passed 
     except ValueError: 
      if 'format_string' in kwargs: 
       format_string = kwargs.pop('format_string') 
       import warnings 
       warnings.warn("Passing 'format_string' as keyword argument is " 
           "deprecated", DeprecationWarning, stacklevel=2) 
      else: 
       raise TypeError("format() missing 1 required positional " 
           "argument: 'format_string'") from None 
     return self.vformat(format_string, args, kwargs) 

这是Python的源在/Lib/string.py

我不知道在哪里的源string.format()生存,所以如果这个Formatter.format()不是这样的话,请不要告诉我,我想要做的就是学习类似string.format()的实现细节。这只是我想要做的一个例子,目的是为了提高我对Python过去的初级水平的理解。

回答

2

您试图导航到的功能是在C中实现的.PyCharm不支持​​导航到CPython源代码中标准库函数的源代码。

+0

有趣和有益的,但不是正确的答案。如果在Python中可以调用list(),那么在Python中必须有类列表的实现。我选择了一个不好的例子,并且会纠正这个问题。 – LostNomad311

+0

你怎么知道这不是一个正确的答案?我对CPython的实现非常熟悉。列表类是在这个文件中实现的,它是用C编写的,而不是Python:https://hg.python.org/cpython/file/tip/Objects/listobject.c – yole

+1

string.format的实现是[here] (https://hg.python.org/cpython/file/tip/Objects/unicodeobject.c#l13791),它也是一个C文件。 – yole