سؤال

I'm using PySide with PyCharm. When I want to jump to the source of a PySide class of method in editor, it always tell me:

Cannot find declaration to go to     

I checked the dir python27/Lib/site-packages/PySide, there are many .pyc and .pyd files, but few *.py. I also download the source package from PySide site, but there are many .cpp and .xml files there.

How can I find the .py sources of PySide and let PyCharm to find them? Or I have to read the docs, which is not that convenient.

هل كانت مفيدة؟

المحلول

You may be misunderstanding something. .pyd files (that file extension is specific to windows, but the principle also applies to .so files on Linux and whatever file extension other systems use) are extensions written in C or C++ compiled to native code and put into a dynamically-linked library.

While you could look at the source if the project in question is open-source (in the case of PySide, it is), it's not Python (do you know C? C++? Quite a few good Python programmers don't) and littered with boilerplate code that contributes nothing but making the cross-language functionality happen. To make matters worse, in the case of PySide the C++ source code is generated automatically (from a tool called Shiboken, which presumably processes the xml files you've seen). You could also look at the source of the Qt functions that are wrapped, but again, this unlikely to buy you much.

So the bottom line is: You'll have to stick with the documentation (or read the original Qt documentation; I found it simple enough to translate to Python when I was using PyQt a while ago). Unless it's absolutely terrible (and the original Qt documentation isn't), it will also answer your question:

  1. Sooner and with less effort. No need to make your way through thousands of lines of code just to get a rough idea of what that paramter implies.
  2. Better. Things like best practices, deprecation warnings and gotchas aren't always visible from the code alone.
  3. More correctly. Can you understand the code correctly, especially at first glance? I wouldn't bet I could.
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top