Most efficient way to concatenate strings in Python!

The most efficient way is to use a list comprehension like so:


def method6():
return ''.join([`num` for num in xrange(loop_count)])


See the whole rundown on the 6 possible ways to do it and their relative efficiency.

I sort of like method 4...

Labels:

Posted at 11:24 PM | 0 comments read on

Python Eggs tutorial

Here's a good introduction and tutorial on python eggs.

Labels:

Posted at 11:23 PM | 0 comments read on

How to install mod_python on XAMPP

Complete tutorial for getting mod_python set up on XAMPP so you can work on Python and Django projects on your localhost computer.

Installing Python (mod_python) on XAMPP (on Windows)

XAMPP + Python + Django

Labels: , ,

Posted at 2:26 PM | 0 comments read on

How to Use the Django Sites Framework

Instructions from the Django Book are skimpy.


How to Use the Sites Framework

The sites framework is more a series of conventions than a framework. The whole thing is based on two simple concepts:

The Site model, found in django.contrib.sites, has domain and name fields.

The SITE_ID setting specifies the database ID of the Site object associated with that particular settings file.

How you use these two concepts is up to you, but Django uses them in a couple of ways automatically via simple conventions.

To install the sites application, follow these steps:

Add 'django.contrib.sites' to your INSTALLED_APPS.
Run the command manage.py syncdb to install the django_site table into your database. This will also create a default site object, with the domain example.com.

Change the example.com site to your own domain, and add any other Site objects, either through the Django admin site or via the Python API. Create a Site object for each site/domain that this Django project powers.

Define the SITE_ID setting in each of your settings files. This value should be the database ID of the Site object for the site powered by that settings file.


Here's another clue.

And perhaps a better way to do this.

The official documentation.

The closest thign toa tutorial:


Next you’ll want to create separate settings files for each domain you’re adding; each one will need its own MEDIA_URL and other settings. You’ll also want to do two things to make sure everything works out properly for administering the different sites:

Create a new Site object in your admin for each domain, and put the id of that Site into its settings file as SITE_ID so Django knows which site in the database corresponds to this settings file.

In the settings file for your original site (the one with id 1), add the other sites’ settings files to the ADMIN_FOR setting, to let Django know that this one instance of the admin application will handle all of the sites.

Now you can use the single Django admin running on your domain to create weblogs which will show up on your friends’ domains.


A couple more leads:

deploying with django's sites framework on webfaction

Serving Multiple Hosts from a Single Django Instance

Labels: ,

Posted at 4:29 PM | 0 comments read on

Python decorators tutorial

Python decorators tutorial recommended beginners look at decorators in Python.

Labels:

Posted at 6:37 PM | 0 comments read on

How to Install and Run Django on Windows (Vista)

Download the Django file from the website.

It's tarred and gunzipped, so use 7-zip to extract it.

Put the extracted directory somewhere.

In your console, cd to the directory (Django-0.96.1 or whatever).

Run this command in the console:
python setup.py install

Start python by typing 'python' at the command line.

Then type:
>>> import django
>>> django.VERSION
(0, 96.099999999999994, None)

Add to your path (see my post about setting path in Vista):
c:\Django-0.96.1\django\bin

You may need to restart console if the path doesn't update (if you changed it via windows see my blog post.)

Then do:
C:\django_projects>django-admin.py startproject mysite

that creates the directory with 4 python files

mysite/
__init__.py
manage.py
settings.py
urls.py


Then start the server that it comes with:

C:\django_projects\mysite>python manage.py runserver
Validating models...
0 errors found.

Django version 0.96.1, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.


Now go to:
http://localhost:8000/

Now you have Django on Windows!

Labels: , ,

Posted at 11:54 AM | 1 comments read on