Introduction To Python - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Introduction To Python

Description:

Introduction To Python. Scripting language. Can learn in a day. Very ... Programming in OSS is a collaborative endeavour between the programmer and the enduser ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 18
Provided by: foss
Category:

less

Transcript and Presenter's Notes

Title: Introduction To Python


1
Introduction To Python
  • Scripting language
  • Can learn in a day
  • Very little typing
  • for (i0ilt10i)
  • print i - 37 keystrokes
  • for i in range(10)
  • print i - 27 keystrokes
  • python dictionary
  • dic 'name''john','age'12
  • dic'name' john

2
Perspective
  • OSS view point
  • End users view point
  • Programming in OSS is a collaborative endeavour
    between the programmer and the enduser
  • Goal get the enduser to do most of the work

3
Web Programming Basics
  • End user should be able to change
  • Data stored in a database - postgresql
  • Site served by apache
  • Business logic scripted in python
  • All display handled by templates
  • Do not put code in your html
  • Do not put html in your code

4
Python CGI Module
  • Unlike the perl cgi, there are no methods to
    generate html
  • cgitb module
  • cgi.FieldStorage()
  • has_key()
  • getfirst()
  • getlist()
  • t cgi.FieldStorage()
  • if t.has_key('submit')
  • name t.getfirst('name')
  • cookies

5
Templates
  • A good template module
  • no programming logic in the template
  • does not interfere with the html code
  • should be usable by a non programmer
  • Cheetah
  • t Template(filefilename,dictdict)
  • print "Content-Type text/html\n\n"
  • print t
  • uses for syntax and for variables

6
Database Connection
  • Psycopg
  • dbi psycopg.connect(dbnamedbname hosthost
    useruser paswordpass)
  • con dbi.cursor()
  • con.execute("select from table")
  • li con.dictfetchall()
  • for k in li
  • k'date' datetostring(k'date')
  • k'amount' str(k'amount').rjust(9)
  • gives an list of dictionaries with the column
    names as keys

7
Template 1
  • include './hhead.tmpl'
  • msg
  • lttable class 'main' border1 align'center'gt
  • ltform action"manpay.py" method"POST"gt
  • lttrgt
  • ltthgtEnter Idlt/thgtlttdgtltinput type"text"
    name"tide" value 'parms'tide'' gtlt/tdgt
  • lttdgtltinput type"submit" value"Search by tid"
    name"tidesearch"gtlt/tdgt
  • lt/trgt
  • lt/tablegt
  • lttable border"1" cellspacing"0"
    cellpadding"5" class'main' align'center'gt
  • lttrgt
  • ltth gtSelectlt/thgtltth gtIdlt/thgtltth gtNamelt/thgtltth
    gtAmountlt/thgtltth gtExpireslt/thgtltth gtStatuslt/thgtltth
    gtTransidlt/thgt
  • lt/trgt

8
Template 2
  • for s in tlist
  • lttrgt
  • lttd gtltinput type'radio' name'chosen'
    values'description'gtlt/tdgt
  • lttd gts'description'lt/tdgt
  • lttd gts'name'lt/tdgt
  • lttd align'right'gts'amount'lt/tdgt
  • lttd gts'expiry'lt/tdgt
  • ltTd gts'status'lt/tdgt
  • ltTd gts'tid'lt/tdgtlt/trgt
  • end for
  • lttrgtltTh colspan"4" align"center"gtltinput
    type"submit" value"Mail" name"mail"gtlt/Thgt
  • ltTh colspan"4" align"center"gtltinput
    type"submit" value"Delete" name"delete"gtlt/Thgtlt/
    trgt
  • lt/tablegtlt/formgt
  • include './hfoot.tmpl'

9
Snapshot of Web Page
10
Python script 1
11
Python Script 2
12
Graphics gdmodule
  • im gd.image((110,40))
  • white im.colorAllocate((255, 255, 212))
  • black im.colorAllocate((0, 0, 183))
  • red im.colorAllocate((235, 239, 255))
  • blue im.colorAllocate((0, 0, 255))
  • im.filledRectangle((0,0),(110,40),black)
  • im.arc((55,20),(105,36),0,360,white)
  • im.fill((55,20),red)
  • im.string_ttf(FONT, 10.0, 0.0, (7, y), text,
    black)
  • fcStringIO.StringIO()
  • im.writePng(f)
  • print "Content-Type image/png\n\n", f.getvalue()
  • f.close()
  • Template
  • ltimg src"gddemo.py" gt

13
Session Management
  • Http a stateless protocol
  • Cookies
  • File and database storage
  • Session Dictionary elements
  • Ttl, first, last, accesses
  • Key value pairs for info
  • Encryption ezpycrypto module

14
Other Python Modules
  • Python Imaging Library
  • HTMLgen
  • Quixote, PSP, PSO
  • Zope and Plone
  • Python Hosting
  • Learning Python

15
Zope management screen
16
View The Page
17
About
  • lawgon_at_thenilgiris.com
  • http//avsap.sourceforge.net
  • http//digiqual.sourceforge.net
  • TkDatePick on cpan
Write a Comment
User Comments (0)
About PowerShow.com