PyCharm does this automatically now by use of Code -> Optimize Imports. It also sorts them into groups per PEP 8.
See https://www.jetbrains.com/help/pycharm/optimizing-imports.html for details.
Answer from Quark on Stack OverflowPyCharm does this automatically now by use of Code -> Optimize Imports. It also sorts them into groups per PEP 8.
See https://www.jetbrains.com/help/pycharm/optimizing-imports.html for details.
PyCharm sorts imports only according to groups specified in PEP-8, not alphabetically.
How do I optimize imports in Python using PyCharm? - Stack Overflow
How to stop Pycharm adding imports to my code automatically ?
pycharm - Is there a shortcut to merge import statements - Stack Overflow
Optimize Imports not completely working correctly...
Videos
It fails every time, it is really stupid how it works.
Just using a new variable name and if that is reused in another module, it adds an import statement on the top, without asking.
Hi - I'm using the optimize imports functionality and it mostly works but it misses some libraries. The ones I've seen so far are tqdm and dateutil. Here's what it looks like after I optimize the imports. Any idea why this is happening / how to fix it? Note that from tqdm import tqdm is grouped with the django imports:
import csv
import json
from datetime import datetime
from decimal import Decimal
from itertools import chain
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.core.cache import cache
from django.db.models import (Avg, Count, ExpressionWrapper, F, FloatField, Q, Sum, fields)
from django.http import HttpResponse, StreamingHttpResponse
from django.shortcuts import render
from tqdm import tqdm
from common.dashboard_util import (construct_cache_name, correct_start_dates, get_all_drilldown_objects,
get_dates_for_columns, get_drilldown_object_id, get_landing_page_variables,
get_lookup_values_by_time_period, get_master_query_from_slug, get_time_to_find)
from core.util import (get_parent_object_from_slug)
from eclose.models import eCloseDefaultFilter
from loan.models import Loan