Presentation is loading. Please wait.

Presentation is loading. Please wait.

Python 20021080 Hyunjong Lee. contents  Introduction  Syntax & data types  Tools  Python as CGI.

Similar presentations


Presentation on theme: "Python 20021080 Hyunjong Lee. contents  Introduction  Syntax & data types  Tools  Python as CGI."— Presentation transcript:

1 Python 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!“  name:  name:

8 Python as CGI  template.html Python is Fun! Python is Fun!

9 Python as CGI  #!/usr/bin/python  #!/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(" ", 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 


Download ppt "Python 20021080 Hyunjong Lee. contents  Introduction  Syntax & data types  Tools  Python as CGI."

Similar presentations


Ads by Google