Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6026323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:25:44+00:00 2026-05-23T04:25:44+00:00

If an object is a module’s class or function I need to retrieve the

  • 0

If an object is a module’s class or function I need to retrieve the absolute import path as a string. Example:

>>> from a.b.c import foo
>>> get_import_path(foo)
'a.b.c.foo'

I tried to look into inspect module but there’s nothing to do that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:25:45+00:00Added an answer on May 23, 2026 at 4:25 am

    What your are trying to do is inherently impossible. foo simply does not know how you imported it — it might even have been imported in multiple different ways. Example on my Linux box:

    >>> from os.path import normpath
    >>> from posixpath import normpath as normpath2
    >>> normpath is normpath2
    True
    

    So normpath and normpath2 are the same function object. It’s impossible to deduce the information in which way they were imported.

    That said, it sometimes might help to look at the __module__ attribute of your function:

    >>> normpath.__module__
    posixpath
    >>> normpath2.__module__
    posixpath
    

    The __module__ attribute is not always defined, and if it is defined, it does not always contain the information you are looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

>>> from PyQt4 import QtCore >>> str = QtCore.QString('Hello') AttributeError: 'module' object has no
Suppose I have a class module clsMyClass with an object as a member variable.
I have a python module that defines a number of classes: class A(object): def
In Windows, the ctypes.cdll.msvcrt object automatically exists when I import the ctypes module, and
public class Module { // required instance variables private String codeModule, titleModule; private int
With Python2.6, the Evt module (from Carbon import Evt) does not have seem to
I am having some trouble importing a class from a particular module. The class
I am trying to call a function in a class based on the string
I have a Python module that I import from my C++ code (I'm embedding
How can a Python program easily import a Python module from a file with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.