I found an interesting python development method that can be done from a usb drive.

portable python

portableapps.com has many interesting apps:

1. commandprompt portable

2. notepad++ portable

3. sumatrapdf portable

4. putty portable

5. winscp portable

etc.

After installing portablepython

execute

SPE-Portable.exe

open manage.py

and run (F9) with argument “runserver”

Then,

import datetime

If you don’t want to refer to the elements of a collection by their position number but prefer some other type of object as a key,

use a python dictionary

———–

e.g.,

>>> tel = {'jack': 4098, 'sape': 4139}
>>> tel['guido'] = 4127
>>> tel
{'sape': 4139, 'guido': 4127, 'jack': 4098}
>>> tel['jack']
4098
>>> del tel['sape']
>>> tel['irv'] = 4127
>>> tel
{'guido': 4127, 'irv': 4127, 'jack': 4098}
>>> tel.keys()
['guido', 'irv', 'jack']
>>> 'guido' in tel
True

Python list and tuple, both of them consists of multiple objects identified its position.

list

L=[1, 2, 3]

tuple

T=(1,2,3)

Difference between them is that tuple is immutable.

That is,

L[0]=100

is OK, but

T[0]=100

is not allowed.

Python tuple

consist of a number of objects which can be referenced by their position number within the object.

———

e.g.,

fruit = (“Apple”,”Banana”,”Cherry”,”Fig”,”Grapefruit”)

__unicode__

is for displaying objects.

———–

For example,

>>>p = Card.objects.create(name=’Hot Pot’, city=’San Diego’)

>>>card_list = Card.objects.all()

>>>card_list

[<Card: Card object>]

without __unicode__, you will see just “Card object”

if you define __unicode__

def __unicode__(self):

return self.name

then, you will see

[<Card: Hot Pot>]

Python list

isĀ  a container that holds a number of other objects, in a given order.

L=[1, 2, 3, 4]

Pygments

takes a source code and

outputs a beautiful looking code.

def func(*args, **kwargs):

Python functions and methods can pass and receive arguments in two forms:

1. positional argument (the order is important)

2. keyword argument(names along with the values)

In Python, list and dictionary types are used for positional and keyword arguments respectively.

Passing a list as an argument and prefixing it with a single asterisk(*) will cause each item of the list in order. This will be used as a separate positional argument.

Passing a dictionary and prefixing it two asterisks(**) will cause the keys of the dictionary to be used as names for separate keyword arugments and the dictionary’s values to become the values of these arguments.

lower()

is a Python string method to return a string converted to lowercase

—-

e.g.,

def get_absolute_url(self):

return “/card/%s/%s/” % (self.pub_date.strftime(“%Y/%b/%d”).lower(), self.slug)

© 2011 Web Oom Suffusion theme by Sayontan Sinha
Switch to our mobile site
Page 2 of 4«1234»Top Footer