0

I'm not that fluent in Python so I'm not sure if what I'm doing is common practice or the proper way to do it.

I'm creating a module archive contaning files with one class each, e.g. SmsArchiveReader.py with class SmsArchiveReader inside. To make the imports less tedious, I decided to import the classes directly into the __init__.py.

However, both Spyder and Pylint have issues with my __init__.py, with Spyder telling me that I shouldn't have unused imports, and Pylint telling me that I shouldn't use absolute imports. Both suggestions seem pointless to me, since this is __init__.py we're talking about, but I'm open to suggestions.

Image below:Spyder reaction

As for the look I wanted to achieve, I wanted the code using this module to look like that:

import archive

myReader = archive.SmsArchiveReader()
myReader2 = archive.FooArchiveReader()

instead of:

import archive

myReader = archive.SmsArchiveReader.SmsArchiveReader()
myReader2 = archive.FooArchiveReader.FooArchiveReader()

So what's the correct practice of creating modules?

Zaroth
  • 568
  • 7
  • 19
  • 2
    Spyder is wrong - `__init__.py` files *generally* have unused imports. I agree with Pylint though, I would use `from .SmsArchiveReader import SmsArchiveReader`. – jonrsharpe Feb 27 '15 at 14:18
  • Wow - I didn't even know ``from .foo import bar`` was a thing. I'll use that and stop disabling the pylint warning, thanks! – Zaroth Feb 27 '15 at 14:23
  • 1
    No problem. It is a little controversial, though; see e.g. http://stackoverflow.com/q/4209641/3001761 – jonrsharpe Feb 27 '15 at 14:26

1 Answers1

0

As jonrsharpe said, it's a problem with Spyder IDE. This issue has been submitted to their bug tracker, the interested can follow its status on Github.

Zaroth
  • 568
  • 7
  • 19