Automatically organize module imports

T

Thomas Wittek

Hi!

Is there any possibility/tool to automatically organize the imports at
the beginning of a module?

I don't mean automatic imports like autoimp does as I like seeing where
my objects/functions really come from.
For the same reason I don't like "from foo import *".

The downside is that you have a rather verbose import section at the
beginning of your code.
That's very bad if you reorganize your code and some imports are not
needed anymore or new imports are needed.
In Eclipse/Java there is a nice feature that automatically organizes
your imports, meaning that it removes unneded imports and even adds
missing imports automatically.

Unfortunately, this PyDev doesn't have an equally powerful feature.
As of the current version it only sorts the imports alphabetically, what
isn't very useful.

So, is there anything I can do about my imports?
Is there a tool that can organize my import section?
Shall I fall back to ambiguous imports like *?
Shall I write out the module name for every class/function that I use
(quite unhandy)?

Thank you!
 
A

Andrew Durdin

Pyflakes will tell you which imports aren't being used (among other
things). I don't know if an existing tool which will automatically
rewrite your source, though.

I'll second that recommendation of Pyflakes -- as the interpreter only
lets you know about undefined names when the code is executed, I find
Pyflakes really useful at finding missing imports (or other undefined
names) as soon as possible.

As I'm doing a lot of work with Django at the moment, which requires
some configuration of the environment to run, the fact that Pyflakes
reads the source without trying to execute any of it helps a great
deal.

Andrew.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top