7

In Python: what is a "qualified name" or "unqualified name"?

I've seen it mentioned a couple of times, but no explanation as to what it is.

Community
  • 1
  • 1
Niels Bom
  • 8,728
  • 11
  • 46
  • 62

1 Answers1

12

It is the path from top-level module down to the object itself.

See PEP 3155, Qualified name for classes and functions.

If you have a nested package named foo.bar.baz with a class Spam, the method ham on that class will have a fully qualified name of foo.bar.baz.Spam.ham. ham is the unqualified name.

A qualified name lets you re-import the exact same object, provided it is not an object that is private to a local (function) namespace.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Are objects the only thing that have qualified names? Or can classes also have them? (Or is a class an object as well?) – Niels Bom Jul 02 '13 at 08:16
  • Does a module have a qualified name? – Niels Bom Jul 02 '13 at 08:16
  • And what is the difference (if any) between a qualified name and a fully qualified name? – Niels Bom Jul 02 '13 at 08:17
  • 3
    Classes are objects; modules (objects too!) have a qualified name, that is what you use when you use an absolute import. Qualified names are not as formal as you think they are; the terms are not that ridgidly defined. – Martijn Pieters Jul 02 '13 at 08:23