Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you organize imports in Eclipse with Pydev?

Tags:

eclipse

pydev

I'm looking for ways to sort and to remove unused imports. Cmd+Shift+O just adds used modules.

(Apologies if this is a duplicate, I really can't find anything non-Java.)

like image 367
chm Avatar asked Apr 04 '14 10:04

chm


2 Answers

Another two steps method is :

  1. Cmd+Shift+O to sort the existing imports (and may be pull some new ones)
  2. Run Pylint or PyFlakes to spot unused imports

This way you will avoid the trap of PyDev not finding imports.

like image 54
JoJo Avatar answered Sep 22 '22 09:09

JoJo


I don't know a simple way to do this. My approach is two step:

  1. Delete all imports (or comment them out)
  2. Cmd+Shift+O to build a new set of imports

But PyDev can't always figure out which modules you need (especially when you use aliases), so this isn't foolproof. Always make sure you can revert your changes.

like image 34
Aaron Digulla Avatar answered Sep 18 '22 09:09

Aaron Digulla