Relative imports

C

Chris

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
 
C

Chris

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 ?
 
K

Kent Johnson

Chris said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,222
Messages
2,571,138
Members
47,755
Latest member
Grazynkaa

Latest Threads

Top