By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,681 Members | 997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,681 IT Pros & Developers. It's quick & easy.

Relative imports

P: n/a
Why do relative imports cause warnings in PyLint?
A warning like this:
ID:W0403 Relative import 'myPythonFileInTheSameFolder'
When the import is like:
from myPythonFileInTheSameFolder import MyClass

Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Chris wrote:
Why do relative imports cause warnings in PyLint?


http://www.python.org/peps/pep-0328....solute-imports
--
Michael Hoffman
Jul 18 '05 #2

P: n/a
Michael Hoffman wrote:
Chris wrote:
Why do relative imports cause warnings in PyLint?

http://www.python.org/peps/pep-0328....solute-imports


I notice that this section says that
from __future__ import absolute_import

will be a feature of Python 2.4. Apparently it didn't make the cut. I've posted a bug report.

Kent
Jul 18 '05 #3

P: n/a
After reading that link I tried to change my imports like this:
" from .myPythonFileInTheSameFolder import MyClass"

Well, this caused an error in PyLint:
Encountered "." at line 1, column 6. Was expecting one of: "or" ...
"and" ... "not" ... "is" ... "in" ... "lambda" ...
"if" ... "else" ... "elif" ... "while" ... "for" ...
"try" ... "except" ... "def" ... "class" ...
"finally" ... "print" ... "pass" ... "break" ...
"continue" ... "return" ... "yield" ... "import" ...
"from" ... "del" ... "raise" ... "global" ... "exec"
.... "assert" ... "as" ... <NAME> ...
ID:E0001 invalid syntax

I'm getting more and more confused...
How can I correctly do a relative import ?

Jul 18 '05 #4

P: n/a
Chris wrote:
After reading that link I tried to change my imports like this:
" from .myPythonFileInTheSameFolder import MyClass"
This style of import is not yet implemented.
I'm getting more and more confused...
How can I correctly do a relative import ?


I think your choices are
- keep doing what you have been doing and ignore the warnings from PyLint
- keep doing what you have been doing and turn off the warnings from PyLint
- rewrite your imports to be absolute imports

Kent
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.