Skip to main content

Resolver for Python dotted names.

Project description

zope.dottedname

Resolve strings containing dotted names into the appropriate python object.

See src/zope/dottedname/README.txt for more information.

Travis: buildstatus winbot: winbotstatus

Dotted Name Resolution

The zope.dottedname module provides one function, resolve that resolves strings containing dotted names into the appropriate python object.

Dotted names are resolved by importing modules and by getting attributes from imported modules. Names may be relative, provided the module they are relative to is supplied.

Here are some examples of importing absolute names:

>>> from zope.dottedname.resolve import resolve

>>> resolve('unittest')
<module 'unittest' from '...'>

>>> resolve('datetime.datetime')
<type 'datetime.datetime'>

>>> resolve('datetime.datetime.now')
<built-in method now of type object at ...>

>>> resolve('non existent module')
Traceback (most recent call last):
...
ImportError: No module named non existent module

>>> resolve('__doc__')
Traceback (most recent call last):
...
ImportError: No module named __doc__

>>> resolve('logging.foo')
Traceback (most recent call last):
...
ImportError: No module named ...foo

>>> resolve('os.path.split').__name__
'split'

Here are some examples of importing relative names:

>>> resolve('.split', 'os.path')
<function split at ...>

>>> resolve('..system', 'os.path')
<built-in function system>

>>> resolve('...datetime', 'os.path')
<module 'datetime' ...>

NB: When relative names are imported, a module the name is relative to must be supplied:

>>> resolve('.split').__name__
Traceback (most recent call last):
...
ValueError: relative name without base module

Changes

4.1.0 (2014-12-26)

  • Add support for PyPy3.

  • Add support for Python 3.4.

  • Add support for testing on Travis.

4.0.0 (2013-02-05)

  • Made tests pass on Python 3.2, 3.3 and PyPy.

  • Add support for continuous integration using tox.

3.4.6 (2009-09-15)

  • Make tests pass on python26.

3.4.5 (2009-01-27)

  • Move README.txt in the egg, so tests works with the released egg as well.

3.4.4 (2009-01-27)

  • Fix ReST in README.txt, fix broken tests with recent zope.testing.

3.4.3 (2008-12-02)

  • More documentation and tests.

3.4.2 (2007-10-02)

  • Fix broken release.

3.4.1 (2007-10-02)

  • Update package meta-data.

3.4.0 (2007-07-19)

  • Initial Zope-independent release.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zope.dottedname-4.1.0.tar.gz (7.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page