Relative imports

Discussion in 'Python' started by Chris, Mar 5, 2005.

  1. Chris

    Chris Guest

    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
     
    Chris, Mar 5, 2005
    #1
    1. Advertising

  2. Michael Hoffman, Mar 5, 2005
    #2
    1. Advertising

  3. Chris

    Kent Johnson Guest

    Kent Johnson, Mar 5, 2005
    #3
  4. Chris

    Chris Guest

    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 ?
     
    Chris, Mar 5, 2005
    #4
  5. Chris

    Kent Johnson Guest

    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
     
    Kent Johnson, Mar 5, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Randall Smith

    Writing apps without using relative imports

    Randall Smith, Dec 3, 2004, in forum: Python
    Replies:
    0
    Views:
    298
    Randall Smith
    Dec 3, 2004
  2. John Salerno

    help with relative imports

    John Salerno, Sep 19, 2006, in forum: Python
    Replies:
    5
    Views:
    328
    John Salerno
    Sep 19, 2006
  3. Albert
    Replies:
    4
    Views:
    10,890
    Albert
    Jul 10, 2008
  4. zildjohn01
    Replies:
    0
    Views:
    654
    zildjohn01
    Feb 22, 2011
  5. Victor Hooi
    Replies:
    1
    Views:
    108
    Devin Jeanpierre
    Nov 25, 2013
Loading...

Share This Page