SlideShare uma empresa Scribd logo
1 de 43
Baixar para ler offline
Adorable Python
     Jerry Peng
What We Are Gonna Talk About

●   Python First Impression
●   The Python Language
●   Python and Linux
●   Python and the Web
●   The Python Community
●   Where to Start
Python First Impression?




      print “Hello World”
Python First Impression
Python First Impression

●
    强制缩进
      –   代码风格一致
      –   编辑器 Tab/Space 的设置很重要
            ●
                用空格而不用制表符
●
    显式声明 self 参数( this )
●
    动态语言
The Python Language

●
    优雅、明确、简单
     –   用一种办法,最好只用一种办法来做一件事
     –   良好的可读性
●
    通用脚本语言
     –   胶水语言
     –   良好的扩展性
     –   良好的模块化支持
     –   完全动态,易于编写和调试
The Python Language

●
    完全面向对象
     –   一切都是对象
           ●
               没有 Java 中的基本类型和对象类型之分
     –   继承、重载、多态的完整支持
           ●
               不鼓励过度抽象的 Java 式设计
The Python Language

●
    有限但够用的函数式特性
     –   匿名函数 lambda
     –   高阶函数
           ●
               接受函数作为参数
           ●
               返回函数
     –   内置的函数式风格 API
           ●   map/filter/reduce, functools
The Python Language

●
    内置数据结构
     –   List
                ●   [item1, item2, item3]
     –   Tuple
                ●   (item1, item2, item3)
     –   Dict
                ●   {key1: value1, key2: value2}
     –   Set
                ●   {item1, item2, item3} (Python 3 Only)
The Python Language

●
    强大、完整的标准库
     –   数据结构和算法、数值运算
     –   文件 / 目录操作
     –   文件解析 / 网络协议 /XML/HTML
     –   OS 服务
     –   多线程 / 多进程
     –   多媒体
     –   GUI(Tk)
Python and Linux
Python and Linux

●
    在 Linux 世界一直很有地位
      –   大量库都有 Python 绑定
            ●
                试试搜索 Ubuntu 中“ python-” 开头的包
●
    Perl 的替代品
      –   文本处理仍不如 Perl ?
●
    适合 Linux 玩家实现各种好玩的程序
Linux Apps Powered By Python

●   Gentoo Portage
●   Ubuntu Tweak
●
    iBus 输入法
●
    Deluge BT 客户端
●
    Exaile 音乐播放器
●
    Mercurial, Bazaar 版本控制系统
Linux Apps Powered By Python

●   Frets on Fire
       –   跨平台、开源的“吉他英雄”
       –   PyGame, PyOpenGL
       –   [OT] 喜欢摇滚的同学一定要试试!
Python and the Web

●
    2005 年 Ruby on Rails 的兴起
      –   让人折服的开发效率
●
    百花齐放的 Python Web 框架
      –   Django
             ●   Google App Engine
      –   Web.py
      –   Pylons → Pyramid
      –   Tornado
             ●   Web Server & Web Framework
Python and the Web

●   WSGI
      –   Web Server Gateway Interface
●
    几乎所有的 Python Web Framework 都符合
     WSGI 标准
      –   方便选择不同部署方案
Python and the Web

●
    豆瓣
●   Google
       –   Google 三大语言之一
       –   2011 Google IO Python Session
●   FriendFeed(Facebook)
       –   Tornado 在此诞生
●   Reddit
       –   Pylons
Python and the Web



国内的 Python 职位大部分都是 Web 开发相关,
●


 有志于当 Python 程序员的同学应该有所关注
The Python Community

●
    CPyUG/Python-CN/ 啄木鸟社区
       –   国内最好的 Python 社区
       –   各路高手出没
●   Python List
       –   小心看不过来
●   Python Sites
       –   Http://simple-is-better.com
       –   Http://www.zhimaq.com
Where To Start

●   Books
       –   Dive Into Python 推荐给有编程经验的人
       –   Python 核心编程
       –   简明 Python 教程
●   Python Online Documentation
●   Python Shell
       –   ipython
●
    Python 2 or 3 ?
Personal Python Experience

●
    Java 系统的外围工具
●
    Java 系统补丁工具
●
    NAS 设备核心程序
●
    网络流量监控工具
●
    MPD 专辑封面抓取工具
●
    VeryCD 资源监视器
意犹未尽有木有?
A Little Deeper into Python

●
    Python 中的酷特性
      –   列表解析 List Comprehension
      –   迭代器 / 生成器 Iterator/Generator
      –   函数的魔法
      –   装饰器 Decorator
●
    关于 Pythonic
      –   编码风格
List Comprehension

●
    简洁、可读的生成列表的方法
     –   表达式
     –   for 循环——支持嵌套
     –   If 过滤条件
     –   map/filter 合体
Iterators

●
    迭代器
     –   抽象了顺序访问数据的过程
     –   包含 __iter__ 方法的特殊对象
           ●
               __iter__ 返回的对象必须包含 next 方法
           ●
               next 返回下一个值
           ●
               如果结束了,应该抛出 StopIteration 异常
Iterators
Iterators

●
    遍布 Python 语言的各个角落
      –   For 循环
      –   列表解析
      –   文件对象
      –   ...
Iterators

●   itertools
       –   izip, ifilter, imap
       –   groupby, combination
Generator

●
    用来快速实现 iterator 的工具
      –   形如普通函数
      –   return 变成 yield ,并多次返回
             ●
                 协程 (coroutine)
      –   可以实现 lazy 运算
Generator
Generator

●
    用类似列表解析的方法写 Generator
The Magic of Functions

●
    函数是一等公民
       –   函数也是对象,可以作为函数的参数和返回值
●
    匿名函数 lambda ( FP 中叫闭包 closure )
       –   再也不想碰 Java 的匿名内部类了
●
    函数式风格的 API
       –   map, filter, reduce
●   functools
The Magic of Functions

●
    map/filter 可以被列表解析取代
●
    reduce 是用来归并一组数据的
      –   map/reduce
The Magic of Functions
The Magic of Functions
Decorators

●
    Decorator 装饰器
      –   接受函数作为参数
      –   返回包装过的函数
●
    类似 Java 中的 AOP (面向切面编程)
●
    实现元编程
      –   Web Framework 中常用
Decorators
Decorators
Simple is Better!

●
    可读性第一
●
    保持简单
●
    再好再酷的特性都不要滥用
●
    多实践!
●
    Be Pythonic !
Be Pythonic

●   The Zen of Python
       –   Beautiful is better than ugly.
       –   Explicit is better than implicit.
       –   Simple is better than complex.
       –   Complex is better than complicated.
●
    import this 来看完整的版本
●
    需要积累和沉淀
Be Pythonic

●   What is Pythonic[limodou]
       –   简单、清晰
       –   不要过分强调技巧
       –   尽量使用 Python 已经提供的功能
       –   符合 Python 的思维方式
●
    Pythonic到底是什么玩意儿?[ 赖勇浩 ]
Be Pythonic

●
    Python 编码规范
      –   PEP 008 Style Guide for Python Code
      –   Code Like a Pythonista: Idiomatic Python
Q&A
人生苦短,我用 Python

Mais conteúdo relacionado

Semelhante a Adorable python

与Python一路走来
与Python一路走来与Python一路走来
与Python一路走来leejd
 
简单Pthon教程
简单Pthon教程简单Pthon教程
简单Pthon教程junjun chen
 
Python简明教程
Python简明教程Python简明教程
Python简明教程ingong
 
Python meetup 1
Python meetup 1Python meetup 1
Python meetup 1Vic Yang
 
20121115 Slides
20121115 Slides20121115 Slides
20121115 SlidesTonyq Wang
 
Jupyter 簡介—互動式的筆記本系統
Jupyter 簡介—互動式的筆記本系統Jupyter 簡介—互動式的筆記本系統
Jupyter 簡介—互動式的筆記本系統Chengtao Lin
 
COSCUP 2019 國際開放原始碼專案經營 - 從失敗中學習
COSCUP 2019 國際開放原始碼專案經營 - 從失敗中學習COSCUP 2019 國際開放原始碼專案經營 - 從失敗中學習
COSCUP 2019 國際開放原始碼專案經營 - 從失敗中學習Jen Yee Hong
 
2 Python开发工具链
2 Python开发工具链2 Python开发工具链
2 Python开发工具链March Liu
 
Python First Class
Python First ClassPython First Class
Python First ClassYao Zuo
 
如何用JDK8實作一個小型的關聯式資料庫系統
如何用JDK8實作一個小型的關聯式資料庫系統如何用JDK8實作一個小型的關聯式資料庫系統
如何用JDK8實作一個小型的關聯式資料庫系統なおき きしだ
 
Python网络抓取小试
Python网络抓取小试Python网络抓取小试
Python网络抓取小试greatghoul
 
轻量级Flash服务器开发框架(刘恒)
轻量级Flash服务器开发框架(刘恒)轻量级Flash服务器开发框架(刘恒)
轻量级Flash服务器开发框架(刘恒)FLASH开发者交流会
 
Weibo lamp improvements
Weibo lamp improvementsWeibo lamp improvements
Weibo lamp improvementsXinchen Hui
 
Linux必备知识与Unix基础文化
Linux必备知识与Unix基础文化Linux必备知识与Unix基础文化
Linux必备知识与Unix基础文化Dahui Feng
 
Summary conversatio-python-group-dalian
Summary conversatio-python-group-dalianSummary conversatio-python-group-dalian
Summary conversatio-python-group-dalianwangyuanyi
 
A brief introduction to Python
A brief introduction to PythonA brief introduction to Python
A brief introduction to Pythonbugway
 
Python 于 webgame 的应用
Python 于 webgame 的应用Python 于 webgame 的应用
Python 于 webgame 的应用勇浩 赖
 

Semelhante a Adorable python (20)

与Python一路走来
与Python一路走来与Python一路走来
与Python一路走来
 
简单Pthon教程
简单Pthon教程简单Pthon教程
简单Pthon教程
 
Python简明教程
Python简明教程Python简明教程
Python简明教程
 
Python meetup 1
Python meetup 1Python meetup 1
Python meetup 1
 
20121115 Slides
20121115 Slides20121115 Slides
20121115 Slides
 
Rootkit tw(0224)
Rootkit tw(0224)Rootkit tw(0224)
Rootkit tw(0224)
 
Jupyter 簡介—互動式的筆記本系統
Jupyter 簡介—互動式的筆記本系統Jupyter 簡介—互動式的筆記本系統
Jupyter 簡介—互動式的筆記本系統
 
Python 1-簡介
Python 1-簡介Python 1-簡介
Python 1-簡介
 
COSCUP 2019 國際開放原始碼專案經營 - 從失敗中學習
COSCUP 2019 國際開放原始碼專案經營 - 從失敗中學習COSCUP 2019 國際開放原始碼專案經營 - 從失敗中學習
COSCUP 2019 國際開放原始碼專案經營 - 從失敗中學習
 
2 Python开发工具链
2 Python开发工具链2 Python开发工具链
2 Python开发工具链
 
Python First Class
Python First ClassPython First Class
Python First Class
 
如何用JDK8實作一個小型的關聯式資料庫系統
如何用JDK8實作一個小型的關聯式資料庫系統如何用JDK8實作一個小型的關聯式資料庫系統
如何用JDK8實作一個小型的關聯式資料庫系統
 
Python网络抓取小试
Python网络抓取小试Python网络抓取小试
Python网络抓取小试
 
轻量级Flash服务器开发框架(刘恒)
轻量级Flash服务器开发框架(刘恒)轻量级Flash服务器开发框架(刘恒)
轻量级Flash服务器开发框架(刘恒)
 
Weibo lamp improvements
Weibo lamp improvementsWeibo lamp improvements
Weibo lamp improvements
 
建置Python開發環境
建置Python開發環境建置Python開發環境
建置Python開發環境
 
Linux必备知识与Unix基础文化
Linux必备知识与Unix基础文化Linux必备知识与Unix基础文化
Linux必备知识与Unix基础文化
 
Summary conversatio-python-group-dalian
Summary conversatio-python-group-dalianSummary conversatio-python-group-dalian
Summary conversatio-python-group-dalian
 
A brief introduction to Python
A brief introduction to PythonA brief introduction to Python
A brief introduction to Python
 
Python 于 webgame 的应用
Python 于 webgame 的应用Python 于 webgame 的应用
Python 于 webgame 的应用
 

Mais de Rhythm Sun

长连接服务 WebSocket Service
长连接服务 WebSocket Service长连接服务 WebSocket Service
长连接服务 WebSocket ServiceRhythm Sun
 
Trello workflow by @imRhythm
Trello workflow by @imRhythmTrello workflow by @imRhythm
Trello workflow by @imRhythmRhythm Sun
 
Bitcoin and retail
Bitcoin and retailBitcoin and retail
Bitcoin and retailRhythm Sun
 
Garage cafe keynote peak ji_no_video
Garage cafe keynote peak ji_no_videoGarage cafe keynote peak ji_no_video
Garage cafe keynote peak ji_no_videoRhythm Sun
 
Doc 2011101411284862
Doc 2011101411284862Doc 2011101411284862
Doc 2011101411284862Rhythm Sun
 
Doc 2011101410543721
Doc 2011101410543721Doc 2011101410543721
Doc 2011101410543721Rhythm Sun
 
Doc 2010050608572429
Doc 2010050608572429Doc 2010050608572429
Doc 2010050608572429Rhythm Sun
 
火狐2011 sfd讲稿
火狐2011 sfd讲稿火狐2011 sfd讲稿
火狐2011 sfd讲稿Rhythm Sun
 
Customize snipmate
Customize snipmateCustomize snipmate
Customize snipmateRhythm Sun
 

Mais de Rhythm Sun (12)

长连接服务 WebSocket Service
长连接服务 WebSocket Service长连接服务 WebSocket Service
长连接服务 WebSocket Service
 
Trello workflow by @imRhythm
Trello workflow by @imRhythmTrello workflow by @imRhythm
Trello workflow by @imRhythm
 
Bitcoin and retail
Bitcoin and retailBitcoin and retail
Bitcoin and retail
 
Garage cafe keynote peak ji_no_video
Garage cafe keynote peak ji_no_videoGarage cafe keynote peak ji_no_video
Garage cafe keynote peak ji_no_video
 
Beginning git
Beginning gitBeginning git
Beginning git
 
Doc 2011101411284862
Doc 2011101411284862Doc 2011101411284862
Doc 2011101411284862
 
Doc 2011101410543721
Doc 2011101410543721Doc 2011101410543721
Doc 2011101410543721
 
Doc 2010050608572429
Doc 2010050608572429Doc 2010050608572429
Doc 2010050608572429
 
Outside
OutsideOutside
Outside
 
火狐2011 sfd讲稿
火狐2011 sfd讲稿火狐2011 sfd讲稿
火狐2011 sfd讲稿
 
Customize snipmate
Customize snipmateCustomize snipmate
Customize snipmate
 
Zsh
ZshZsh
Zsh
 

Adorable python

  • 1. Adorable Python Jerry Peng
  • 2. What We Are Gonna Talk About ● Python First Impression ● The Python Language ● Python and Linux ● Python and the Web ● The Python Community ● Where to Start
  • 3. Python First Impression? print “Hello World”
  • 5. Python First Impression ● 强制缩进 – 代码风格一致 – 编辑器 Tab/Space 的设置很重要 ● 用空格而不用制表符 ● 显式声明 self 参数( this ) ● 动态语言
  • 6. The Python Language ● 优雅、明确、简单 – 用一种办法,最好只用一种办法来做一件事 – 良好的可读性 ● 通用脚本语言 – 胶水语言 – 良好的扩展性 – 良好的模块化支持 – 完全动态,易于编写和调试
  • 7. The Python Language ● 完全面向对象 – 一切都是对象 ● 没有 Java 中的基本类型和对象类型之分 – 继承、重载、多态的完整支持 ● 不鼓励过度抽象的 Java 式设计
  • 8. The Python Language ● 有限但够用的函数式特性 – 匿名函数 lambda – 高阶函数 ● 接受函数作为参数 ● 返回函数 – 内置的函数式风格 API ● map/filter/reduce, functools
  • 9. The Python Language ● 内置数据结构 – List ● [item1, item2, item3] – Tuple ● (item1, item2, item3) – Dict ● {key1: value1, key2: value2} – Set ● {item1, item2, item3} (Python 3 Only)
  • 10. The Python Language ● 强大、完整的标准库 – 数据结构和算法、数值运算 – 文件 / 目录操作 – 文件解析 / 网络协议 /XML/HTML – OS 服务 – 多线程 / 多进程 – 多媒体 – GUI(Tk)
  • 12. Python and Linux ● 在 Linux 世界一直很有地位 – 大量库都有 Python 绑定 ● 试试搜索 Ubuntu 中“ python-” 开头的包 ● Perl 的替代品 – 文本处理仍不如 Perl ? ● 适合 Linux 玩家实现各种好玩的程序
  • 13. Linux Apps Powered By Python ● Gentoo Portage ● Ubuntu Tweak ● iBus 输入法 ● Deluge BT 客户端 ● Exaile 音乐播放器 ● Mercurial, Bazaar 版本控制系统
  • 14. Linux Apps Powered By Python ● Frets on Fire – 跨平台、开源的“吉他英雄” – PyGame, PyOpenGL – [OT] 喜欢摇滚的同学一定要试试!
  • 15. Python and the Web ● 2005 年 Ruby on Rails 的兴起 – 让人折服的开发效率 ● 百花齐放的 Python Web 框架 – Django ● Google App Engine – Web.py – Pylons → Pyramid – Tornado ● Web Server & Web Framework
  • 16. Python and the Web ● WSGI – Web Server Gateway Interface ● 几乎所有的 Python Web Framework 都符合 WSGI 标准 – 方便选择不同部署方案
  • 17. Python and the Web ● 豆瓣 ● Google – Google 三大语言之一 – 2011 Google IO Python Session ● FriendFeed(Facebook) – Tornado 在此诞生 ● Reddit – Pylons
  • 18. Python and the Web 国内的 Python 职位大部分都是 Web 开发相关, ● 有志于当 Python 程序员的同学应该有所关注
  • 19. The Python Community ● CPyUG/Python-CN/ 啄木鸟社区 – 国内最好的 Python 社区 – 各路高手出没 ● Python List – 小心看不过来 ● Python Sites – Http://simple-is-better.com – Http://www.zhimaq.com
  • 20. Where To Start ● Books – Dive Into Python 推荐给有编程经验的人 – Python 核心编程 – 简明 Python 教程 ● Python Online Documentation ● Python Shell – ipython ● Python 2 or 3 ?
  • 21. Personal Python Experience ● Java 系统的外围工具 ● Java 系统补丁工具 ● NAS 设备核心程序 ● 网络流量监控工具 ● MPD 专辑封面抓取工具 ● VeryCD 资源监视器
  • 23. A Little Deeper into Python ● Python 中的酷特性 – 列表解析 List Comprehension – 迭代器 / 生成器 Iterator/Generator – 函数的魔法 – 装饰器 Decorator ● 关于 Pythonic – 编码风格
  • 24. List Comprehension ● 简洁、可读的生成列表的方法 – 表达式 – for 循环——支持嵌套 – If 过滤条件 – map/filter 合体
  • 25. Iterators ● 迭代器 – 抽象了顺序访问数据的过程 – 包含 __iter__ 方法的特殊对象 ● __iter__ 返回的对象必须包含 next 方法 ● next 返回下一个值 ● 如果结束了,应该抛出 StopIteration 异常
  • 27. Iterators ● 遍布 Python 语言的各个角落 – For 循环 – 列表解析 – 文件对象 – ...
  • 28. Iterators ● itertools – izip, ifilter, imap – groupby, combination
  • 29. Generator ● 用来快速实现 iterator 的工具 – 形如普通函数 – return 变成 yield ,并多次返回 ● 协程 (coroutine) – 可以实现 lazy 运算
  • 31. Generator ● 用类似列表解析的方法写 Generator
  • 32. The Magic of Functions ● 函数是一等公民 – 函数也是对象,可以作为函数的参数和返回值 ● 匿名函数 lambda ( FP 中叫闭包 closure ) – 再也不想碰 Java 的匿名内部类了 ● 函数式风格的 API – map, filter, reduce ● functools
  • 33. The Magic of Functions ● map/filter 可以被列表解析取代 ● reduce 是用来归并一组数据的 – map/reduce
  • 34. The Magic of Functions
  • 35. The Magic of Functions
  • 36. Decorators ● Decorator 装饰器 – 接受函数作为参数 – 返回包装过的函数 ● 类似 Java 中的 AOP (面向切面编程) ● 实现元编程 – Web Framework 中常用
  • 39. Simple is Better! ● 可读性第一 ● 保持简单 ● 再好再酷的特性都不要滥用 ● 多实践! ● Be Pythonic !
  • 40. Be Pythonic ● The Zen of Python – Beautiful is better than ugly. – Explicit is better than implicit. – Simple is better than complex. – Complex is better than complicated. ● import this 来看完整的版本 ● 需要积累和沉淀
  • 41. Be Pythonic ● What is Pythonic[limodou] – 简单、清晰 – 不要过分强调技巧 – 尽量使用 Python 已经提供的功能 – 符合 Python 的思维方式 ● Pythonic到底是什么玩意儿?[ 赖勇浩 ]
  • 42. Be Pythonic ● Python 编码规范 – PEP 008 Style Guide for Python Code – Code Like a Pythonista: Idiomatic Python