How to get current python module name?

What is the best way to get python module name with given PsiFile/PyFile or PyClass/PyFunction ?

I want something like "py_pack.sub_pack.file_in_sub" for given file_in_sub.py file.

Is there a better way than just take subpath of the file and replace delimiters with dots?

0
1 comment
Avatar
Permanently deleted user
import com.jetbrains.python.psi.resolve.QualifiedNameFinder;

String module = QualifiedNameFinder.findShortestImportableName(psiFile, virtualFile);
0

Please sign in to leave a comment.