Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango/python imports perfomance
    primarykey
    data
    text
    <p>Can somebody please proof why it's a bad practice to use solution like this:</p> <p>In django views in 98% cases you need to use</p> <pre><code> from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse from django.utils.translation import ugettext as _ </code></pre> <p>anyway in my project my every view has these imports and everything is used almost in every second function of a view:</p> <pre><code>from datetime import datetime from django.conf import settings from django.contrib.auth.models import User from django.core.urlresolvers import reverse from django.core import paginator from django.db import connection from django.db.models import Q from django.http import HttpResponseRedirect, Http404, HttpResponse from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext from django.utils.translation import ugettext as _ </code></pre> <p>Now add some models and forms, and I have 50 lines of bullshit that is impossible to read at all. </p> <p>First thing that came to my head is of course to make more views, to split some operation and etc and etc.. but still about 30 lines of imports killing my orientation in code.</p> <p>Then I just decided to put everything that being used in views by 95% of a time, to directory /project/app/imports/view.py. Now I have all common stuff just with <strong>ONE</strong> import, but my co-worker attacked me, that it's highly hard to read this kind of code, because you can't see what is imported, and why the hell it's so hard to open one more tab in your IDE..??? [especially this goes to vim users, they have FRAMES, and he is using vim]</p> <p>I did the same with models, my models has it's own dir, because it's over 50 them in there, and those files are not small - about 150 lines each.. Even these files have few models inside.. so I'm just doing something like : </p> <pre><code>from myapp.models.mymodel import * </code></pre> <p>and there are some places where I just doing: <code>from myapp.models import *</code> [<strong>init</strong>.py of myapp/imports dir takes place in here]</p> <p><strong>Problems:</strong></p> <p>1) ok so first problem is namespace, this kind of model importing is maybe really ridiculous.. but decision with views and forms, is just nothing but lazziness to open one more tab in your IDE</p> <p>2) performance problem? my co-worker really arguing a lot with this argument, that "every import takes 256kb of ram"?? (by running compiled .pyc file? no i don't believe that ;)</p> <p>The question in fact is about performance problem because of imports.</p> <p>p.s. I'm really new in python (just 3 month), and I open to OBJECTIVE arguments for all probs and cons about this solution.</p> <p><strong>UPDATE</strong></p> <p>Once I asked question about how to move imports to standalone file so nobody complained about this =) question is <a href="https://stackoverflow.com/questions/3300568/how-to-move-all-those-imports-to-standalone-file">here</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload