Skip to content

intra-package import statements #3

Closed

Description

@cjerdonek

I have a question regarding simplejson's intra-package import statements. For example, in decoder.py, there is the statement--

from simplejson.scanner import make_scanner

It seems like this prevents simplejson from being used without installing it. If I drop the simplejson package into my project at the location thirdparty/simplejson and use the import statement--

from thirdparty import simplejson as json

then I get the following error at that line of decoder.py:

ImportError: No module named simplejson.scanner

Is there a way to use simplejson in the way that I'm trying without getting that error? If you used relative imports of the form

from scanner import make_scanner  # or
from .scanner import make_scanner

then it seems like this would not be a problem. I know that PEP 8 discourages the use of relative imports, but for the reason above, I've never understood its rationale for packages where the package owner does not have control over how the package will be used. Thanks in advance for your help.

Activity

  1. etrepum commented on Apr 19, 2011

    @etrepum
    Member

    If you submit a pull requests with tests for this I would consider it, but there are other ways to do what you're doing that don't require changing the namespace. Note that it may even require changes to the C code to support this, because it imports Python code.

  2. added a commit that references this issue on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions