1 / 11

Python

Python. 20021080 Hyunjong Lee. contents. Introduction Syntax & data types Tools Python as CGI. Introduction. Developed by Guido Van Rossum in 1990 Interpret based language Has simple syntax Dynamic type binding Embedded high level data structure Garbage collection

mili
Download Presentation

Python

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Python 20021080 Hyunjong Lee

  2. contents • Introduction • Syntax & data types • Tools • Python as CGI

  3. Introduction • Developed by Guido Van Rossum in 1990 • Interpret based language • Has simple syntax • Dynamic type binding • Embedded high level data structure • Garbage collection • Module structure (glue language) • Fast development cycle

  4. Syntax • Syntax is very simple • Similar to most of other languages • Indentation sensitive

  5. High level built-in data types • Complex number • List (can be nested) • Tuples • Dictionary

  6. Tools • Py2exe – convert python script into exe file • Python2c – convert python script into C source file • SWIG(simplified wrapper and interface generator) – glue code generator

  7. Python as CGI • #!/usr/bin/python import cgi #import CGI module print "Content-Type: text/plain\n\n" The_Form = cgi.FieldStorage() for name in The_Form.keys(): print "Input: " + name print " value: " + The_Form[name].value + “\n” print "Finished!“ • <form name="form" method="get" action="http://sid.redfeel.net/~rene/cgi-bin/test.py"><p>email:<input type="text" name="email"> name:<input type="text" name="name"><input type="submit" value=“Run"></p></form>

  8. Python as CGI • template.html <html> <head> <META NAME="keywords" CONTENT="blah blah -- your ad here“> <title>Python is Fun!</title> </head> <body> <!--INSERT CONTENT HERE--> </body> </html>

  9. Python as CGI • #!/usr/bin/python import re #import regular expression module import cgi TemplateFile = "template.html" # Display function def def Display(Content): fp = open(TemplateFile, "r") TemplateInput = fp.read() #open & read entire file fp.close() BadTemplateException = “problem in template file" SubResult = re.subn("<!--INSERT CONTENT HERE-->", Content,TemplateInput) if SubResult[1] == 0: raise BadTemplateException print "Content-Type: text/html\n\n“ print SubResult[0] #make dynamic contents here …

  10. Python as CGI • import MySQLdb # import SQL module connection = MySQLdb.connect(user=‘uuu', passwd=‘ppp', db=‘db') cursor = connection.cursor() cursor.execute(“SELECT * FROM some_table”) cursor.close()

  11. References • http://www.python.or.kr/

More Related