2016-01-29 112 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