Hi, Johan,

To answer the spirit of your question: Mostly, you will get the correct
import locations from the examples you use. Once you're used to Python, you
will see that there is a logic to the imports:

* You start at wherever your virtualenv stores its site-packages if you use
virtualenv, otherwise it should be somewhere in your Python path. For
example, my virtualenv directory is called ve, so I start at
ve/lib/python2.7/site-packages.

* Next you just burrow down the path, keeping in mind the convention that a
python module that you can import from is either a file with the module
name, or a directory with the module name, that has an __init__.py file in
it. For example: The import source above could be in
ve/lib/python2.7/site-packages/django/http.py or in
 ve/lib/python2.7/site-packages/django/http/__init__.py. In our case, the
second one is the right one.

* Note that when you open up that file, you see that it actually imports
the HttpResponse from django.http.response, which sits in the same
directory in the response.py file. This is usually due to a few factors:
Backwards compatibility, more compact imports of related functionality from
elsewhere, or maybe it's just the preferred coding style :)

OK, so that covers django imports, as well as other specific packages in
your requirements files, if you use pip (and you should, really). There are
2 other non-obvious places you will have imports:

1. If you have installed extra python packages globally, you might be able
to import those from other locations in the path. There, you probably need
to open a python debugger and look at sys.path to see where to start
looking for the actual files.

2. Python has many, many modules included, but not imported by default.
These you will encounter as you search for examples on how to do things in
Python. For example, math:

>>> from math import sqrt
>>> sqrt(16)
4

That should cover it. Keep in mind that Python is open source, so you can
find most of this from reading the source code. However, it's all
documented pretty well on the Django site, as well as various Python docs
sites.

Hope this helps,

Johan


> On Tue, Feb 11, 2014 at 5:26 AM, Johan Hendriks <joh.hendr...@gmail.com>wrote:
>
>> Hello all.
>>
>> I have a little question, maybe a little stupid but non the less it keeps
>> me busy. :-)
>>
>> I want to start making some web based apps as a hobby project.
>> I have no coding experience other then some basic shell scripting to get
>> some daily routine jobs done on my FreeBSD servers.
>> The first struggle I had to take is the programming language, I looked at
>> PHP and python, and I think my best option is Python, and with python comes
>> Django.
>> So the last weeks i have been doing some searches on google and view a
>> lot of tutorial video's how to start with django.
>>
>> One thing that always comes back is the import part like below
>>
>> from  django.http  import  HttpResponse
>>
>> And here comes my question, where and how do you know what you need to
>> import.
>> What is the best way to learn al these imports? , and is there a quick
>> way to find the imports you need?
>>
>> Thank you for your time.
>>
>> regards
>> Johan
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMto1Srrg1avEBdZH5v-sVHnUP8BPSER_iGQU%2BMkA3OOpPEyYg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to