Friday, July 11, 2008

Monday, June 16, 2008

Integer division in Python 3.0

>python
Python 2.5.1 (r251:54863, Feb  4 2008, 21:48:13) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 200/400
0
>>> 200.0/400
0.5
>>> from __future__ import division
>>> 200/400
0.5
>>> 200//400
0
>>> print "In Python 3.0 200/400 will yield 0.5"
In Python 3.0 200/400 will yield 0.5
>>> 

Monday, May 26, 2008

Easy Access to Python

Goal: Have methodology for quickly accessing anything about Python. While programming, do not have completed thought process without aid of computer stored information.

>pydoc -g
      |
      |
      +--+ opens Tkinter window

       |
       |
      +-+ open browser
            |
            |
            + Python: Index of Modules
http://python.org/doc/2.5/lib/development.html

Saturday, May 24, 2008

A beautiful presentation of information

epydoc.sourceforge.net/stdlib/httplib-module.html
    (null)
      |
      | HTTPConnection()
      v
    Idle
      |
      | putrequest()
      v
    Request-started
      |
      | ( putheader() )*  endheaders()
      v
    Request-sent
      |
      | response = getresponse()
      v
    Unread-response   [Response-headers-read]
      |\____________________
      |                     |
      | response.read()     | putrequest()
      v                     v
    Idle                  Req-started-unread-response
                     ______/|
                   /        |
   response.read() |        | ( putheader() )*endheaders()
                   v        v
       Request-started    Req-sent-unread-response
                            |
                            | response.read()
                            v
                          Request-sent

Friday, May 23, 2008

NSLOOKUP in Python

from socket import gethostbyaddr 

def nslooky(ip):
      try: 
           output = gethostbyaddr(ip)
           return output[0]
     except: 
           output = "not found" 
           return output

 your_ip = request.META.get('REMOTE_ADDR') 
# above is Django module object
 your_name = nslooky(your_ip)
Original code by Cluther