Python - A Comprehensive Programming Language

2,344 views
2,225 views

Published on

Python - A Comprehensive Programming Language, talk at
1. CSIE, Providence University, 2009/05/08
2. CSIE, National Taichung Institute of Technology, 2009/10/29

Published in: Education, Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,344
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
147
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Python - A Comprehensive Programming Language

  1. 1. Python A Comprehensive Programming Language 胡崇偉 marr@citi.sinica.edu.tw Open Source Software Foundry
  2. 2. 自由軟體鑄造場 • 營運網站以提供自由軟體專案進駐開發 • 提供系統技術與工具以協助軟體開發 • 研究開放源碼軟體授權條款與法律政策 議題並提供諮詢 • 媒合促成以自由軟體為基礎的本地成功 案例 • 報導國內外產業及社群新聞 • 進行人才培育及國際交流活動
  3. 3. Service and Resource 專案管理
  4. 4. Service and Resource 共同筆記 檔案下載 版本管理 專案管理 通信論壇 待辦事項 統計資訊
  5. 5. Service and Resource 資源目錄 共同筆記 人才資料 檔案下載 版本管理 授權條款 專案管理 電子報 精靈 通信論壇 待辦事項 研究報告 統計資訊 推廣光碟 教學文件
  6. 6. 軟體自由協會 • http://www.slat.org/ • 台灣推展軟體自由運動的社團法人 • 執行校園自由軟體應用諮詢中心計畫 • 協助社群代收贊助款項 • 舉辦研討會及推廣活動
  7. 7. Python ?
  8. 8. Python is a Dynamic Object-Oriented Programming Language
  9. 9. Run-Time Typing • Python's run time must work harder than Java's. • a+b=? – inspect the objects a and b to find out their type, which is not known at compile time. – 7 + 11.0 – ‘Hello’ + ‘world’ – (1, 2, 3) + (4, 5, 6)
  10. 10. >>> 是提示符號
  11. 11. Interactive with Interpreter Edit Debug Compile Wait Deploy Print Read Eval Read-Eval-Print Loop
  12. 12. Built-in DataTypes • Number 7, 11.0 elements elements • String ‘Hello World’ • List [7, 11, ‘store’] • Tuple (7, 11, ‘shop’) • Dictionary {‘name’:’marr’, ‘home’:’taipei’} keys
  13. 13. MIT to Try Python in CS Courses
  14. 14. Other Features • Cross Platform and Porting • Excellent Modules • Small • Efficient • Popular
  15. 15. Nokia PyS60
  16. 16. Indexing and Slicing 0 1 2 7 [ ↓ ↓ ↓ -6 ↓ -2 -1 ↓ ↓ ] I L o v e P y t h o n • myString = “I Love Python” • myString[0] == “I” • myString[-1] == “n” • myString[7:-2] == “Pyth”
  17. 17. Code Indenting • No explicit begin or end • No curly braces if age > 18: print “You are old enough.” else: print “You are too young.”
  18. 18. Function Example def myFunc(score): “”” document strings “”” import math math.sqrt(score) * 10
  19. 19. File Handling fileobj = open(“myfile”, “r”) lines = fileobj.readlines() for line in lines: print line
  20. 20. Socket Creation import socket s = socket.socket( socket.AF_INET, socket.SOCK_STREAM) s.connect( ("www.mysite.com", 80))
  21. 21. Twisted - Networking Engine • A web server, numerous chat clients, chat servers, mail servers and more. • Supported protocols: TCP, SSL, multicast, HTTP, IMAP and more • Sample apps: BitTorrent, CIA Bot, BuildBot, apt-proxy2
  22. 22. RestructuredText • http://docutils.sourceforge.net/ • Support Formats: HTML,XML,S5,LaTeX • rst2html < myRST.txt > myRST.html
  23. 23. Version Control • Mercurial
  24. 24. GUI Library and Toolkit
  25. 25. Wingware IDE
  26. 26. Python Package Index
  27. 27. PyGame
  28. 28. PyGame
  29. 29. Blender
  30. 30. Elephants Dream
  31. 31. SQLAlchemy from sqlalchemy import * db = create_engine(‘sqlite:///tutorial.db’) metadata = MetaData(db) users = Table(‘users’, metadata, Column(‘user_id’, Integer, primary_key=True), Column(‘name’, String(40)), ) users.create() i = users.insert() i.execute(name=‘marr’)
  32. 32. Web Frameworks
  33. 33. Python Hosting
  34. 34. Extending and Embedding $ swig -python example.i $ gcc -c example.c example_wrap.c -I/usr/local/include/python2.1 $ ld -shared example.o example_wrap.o -o _example.so >>> import example >>> example.fact(5) 120
  35. 35. Self Learning – Where to Start • On-line Tutorial • Books – Google ‘python tutorial’ – Better in English
  36. 36. Video Tutorials • http://www.showmedo.com/ • http://www.youtube.com/ • http://video.google.com/ • http://www.blip.tv/
  37. 37. Local User Groups • http://python.org.tw/ • http://planet.python.org.tw/ • Facebook: Python Taiwan • Google Group: pythontw • OpenFoundry Forums • Hemidemi: python
  38. 38. Anytime, Anywhere IPython Google App Engine http://shell.appspot.com/
  39. 39. Python-based CMS Case Study
  40. 40. Plone … a CMS Built on Zope Written in Python
  41. 41. Blog (CoreBlog)
  42. 42. Portal (CIA, USA)
  43. 43. Portal (NASA, USA)
  44. 44. Network Management (ZenOSS)
  45. 45. Issue Tracker (Poi)
  46. 46. Download Installer • http://plone.org/products/plone
  47. 47. Windows Installer
  48. 48. Windows Installer
  49. 49. Windows Installer
  50. 50. Plone Controller
  51. 51. Filesystem Listing • Python • Zope • Plone • Packages/Products • Software Home • Instance Home
  52. 52. One Database, Many Instances HTTP Requests and Responses port 8080 port 8081 ZEO Client #1 ZEO Client #2 Data.fs Instance #1 Instance #2
  53. 53. Front Page
  54. 54. Zope Management Interface (ZMI)
  55. 55. Site Setup
  56. 56. Guest View
  57. 57. Authenticated View
  58. 58. - Tip for Trying Out Different Browsers for Different Users/Roles One for Admin, Another for Regular User
  59. 59. Usecase #1 Create a New User
  60. 60. Views Available After Login • Personal Bar • Content Views
  61. 61. Usecase #2 Create New Contents (Page)
  62. 62. Default Content Types Page Image News Item File Event Link
  63. 63. Title to ID (Part of the URL) ↓
  64. 64. Visual Editor
  65. 65. Content States
  66. 66. Default State and Workflow
  67. 67. Roles and Permissions View Add Edit Review Manager ✔ ✔ ✔ ✔ Reviewer ✔ ✔ ✔ Member ✔ ✔ ✔ Non-Login ?
  68. 68. Core Security Mapping
  69. 69. Transaction and Undo
  70. 70. Usecase #3 Manage Portlets
  71. 71. Usecase #4 Enable OpenID Support
  72. 72. Usecase #5 Change Theme (to NuPlone)
  73. 73. Free Themes
  74. 74. Better and Super Plone ?
  75. 75. Want More ? Join the Community and Develop !
  76. 76. Starting Points • http://plone.org/documentation • http://marrtw.blogspot.com/2009/04/plone3-books.html
  77. 77. SQL Database Connection Z SQL Z SQL Z SQL Z SQL Z SQL Z SQL Method Method Method Method Method Method MySQL PgSQL ODBC Database Database Database Connection Connection Connection
  78. 78. Database Components HTML WYSWYG Editor Plone DTML Page Template Site Development and Search Interface Script Management Z SQL Method Database Zope Connection MySQLDA PsycopgDA ODBCDA Database Gadfly Adapter MySQL PostgreSQL MSSQL
  79. 79. Designer Friendly Templates • Work with WYSIWYG editors • Zope Page Template (ZPT) – Template Attribute Language (TAL) – Macro Expansion Tag Attribute Language (METAL) XML Namespace TAL statement name body Attribute Attribute Element Name Value Content <title tal:content="here/title">Page Title</title>
  80. 80. Theme Designers ? • AJAX / jQuery Support • KSS = Kinetic Style Sheets • Deliverance • Must Read – Plone 3 Theming
  81. 81. Repeatable Development editing running with buildout.cfg bin/buildout installed as downloading checking into product/ package *.egg Python Package *.tar.gz Index
  82. 82. Build Your Own Project cd c: C:plonepythonScriptspaster create plone3_buildout MyBuildout cd MyBuildout vim buildout.cfg binbuildout.exe
  83. 83. buildout.cfg Sample [buildout] http-address = 8080 eggs = Plone my.package zcml = my.package debug-mode = on
  84. 84. Summary A Comprehensive CMS 通用型的內容管理系統 The Web CMS Report Ideaware Report
  85. 85. Web CMS 2007 Technology Content Production Services Standards Authoring & Transformation Development Aggregation Access Control Repository Services Templating Metadata/Taxonomy Management Page Rendering Globalization Usability Promotion Path Internationalization System Reporting Content Delivery Services Vendor Intangibles Personalization Maintenance & Support Site Search Integration & Tech Partnerships Scaling & Performance Active User Groups Multichannel & Syndication Services & Channel Content Retention Product QA User-Generated Content Strategy & Roadmap Micro-Applications Good Value Site Analytics
  86. 86. Active Community
  87. 87. Multilingual Support
  88. 88. Open Source Projects ArgoUML SchoolTool
  89. 89. Alternative Theming - Deliverance
  90. 90. Developer Baby Steps • Python Script + External Method
  91. 91. Plone Hosting
  92. 92. Thank You ! Question? Email to marr.tw@gmail.com

×