SlideShare una empresa de Scribd logo
1 de 34
Introduction Python
Roger Xia
Aug 2013
What is
A dynamic object-oriented programming language.
Python is a programming language that lets you
work more quickly and integrate your systems more
effectively. You can learn to use Python and see
almost immediate gains in productivity and lower
maintenance costs.
– http://www.python.org/
Zen
August 2013
Who is using Python?
spider and search engine
Yahoo Maps, Yahoo Groups
Python Success Stories
– http://www.python.org/about/success/
– Star Wars! : http://www.youtube.com/watch?v=RqhUz2vh6lA
– http://lineofthought.com/tools/python
My experience on Python?
• 2007-2010
– Web Automation testing : MaxQ
– Crawler web news for vertical search : beautifulsoup, lxml, mechanize
• 2011
– Text/file processing – hadoop?
• 2013
– scrapy (twisted) vs. gcrawler (gevent)
What Python can do?
• Xml processing
• Web Application
• Off-line computation
• Operation scripts
– puppet/chef(ruby)
– salt(python)
• NLP Processing
– has strong numeric processing capability : matrix
operations, etc
– Suitable for probability and machine learning code.
– NLTK : nature language tool kit
• data analysis
• machine learning
• Big data : R: http://www.xmind.net/m/LKF2/
Python has a simple, minimal, clean syntax
find the roots of a quadratic equation
HTTP Requests
Easy to get started!
• http://www.python.org/doc/
• <<Dive into Python>> : http://www.diveintopython.net/toc/index.html
• Python standard libraries: http://docs.python.org/2/library/index.html
• Google
• PyPI : http://pypi.python.org/pypi
– There are currently 33961 packages
• PyCon : http://www.pycon.org/
• Practice, practice, practice
Getting started and Installation
• Windows : find the install package here
http://www.python.org/download/releases/2.7.5/
• Linux : Generally, python come installed with the operating
system, if not, try
– Centos/redhat : yum install python
– Ubuntu : sudo apt-get install python2.7
– wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz
(./configure & make & make install)
Using the python interpreter
• Indentation/缩进
• #
• “”” (doc string)
• Variables are created when they are assigned.
The name is case sensitive.
• If __name__==“__main__”:
– __name__ is a built-in variable which evaluate to the name of the
current module.
– being run directly or being imported?
Built-in types
• None
• bool : True/False
• int/long/float
• str/unicode (u’Spam’)
• tuple
• list
• dict
• lambda expression
Dictionary
• defines one-to-one relationships between
keys and values /定义了键和值之间一对一的
关系
List
Using lists as stacks/queues
List comprehensions
creating a list based on existing lists
Nested List comprehensions
Built in function
Tuple
• A tuple is an immutable list. A tuple can not
be changed in any way once it is created.
Defining Functions
>>> def fib(start=0, n=2000):
... "Print a Fibonacci series up to n, start from start"
... result = []
... a, b = start, start+1
... while b < n:
... result.append(b)
... a, b = b, a+b
... return result
...
>>> f1 = fib(5)
>>> f1
[6, 11, 17, 28, 45, 73, 118, 191, 309, 500, 809, 1309]
>>> f2 = fib(0, 1000)
>>> f2
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]
Lambda Functions
anonymous functions in python
Type help() for help documents
Python 支持一种有趣的语法,它允许你快速定义单行的最小函数。这些叫做
lambda 的函数,是从 Lisp 借用来的,可以用在任何需要函数的地方。
>>> a = ['Mary', 'had', 'a', 'little', 'lamb']
>>> for i in range(len(a)):
... print i, a[i]
...
0 Mary 1 had 2 a 3 little 4 lamb
others
• Regular expressions:
– http://www.tutorialspoint.com/python/python_re
g_expressions.htm
• Exceptions:
– http://docs.python.org/2/tutorial/errors.html
Modules
• A module is a file containing Python definitions and
statements. The file name is the module name with the
suffix .py appended. Within a module, the module’s name is
available as the value of the global variable __name__.
– A module can contain executable statements as well as function
definitions. These statements are intended to initialize the module.
They are executed only the first time the module name is encountered
in an import statement.
– Each module has its own private symbol table, which is used as the
global symbol table by all functions defined in the module.
– When a module named spam is imported, the interpreter first
searches for a built-in module with that name. If not found, it then
searches for a file named spam.py in a list of directories given by the
variable sys.path.
Packages
• Packages are a way of structuring Python's module
namespace by using "dotted module names".
• The __init__.py files are required to make Python treat the
directories as containing packages; this is done to prevent
directories with a common name
What can you do with excel?
• 1. read/write to normal csv file
• 2. use csv module to do it
• 3. pypi search for excel
– http://www.simplistix.co.uk/presentations/python
-excel.pdf
• >>> import csv
• >>> with open('D:/eggs.csv', 'wb') as csvfile:
• ... spamwriter = csv.writer(csvfile, delimiter=' ', quotechar='|', quoting=cs
• v.QUOTE_MINIMAL)
• ... spamwriter.writerow(['Spam'] * 5 + ['Baked Beans'])
• ... spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])
• ...
• >>> with open('D:/eggs.csv', 'rb') as csvfile:
• ... spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
• ... for row in spamreader:
• ... print ', '.join(row)
• ...
• Spam, Spam, Spam, Spam, Spam, Baked Beans
• Spam, Lovely Spam, Wonderful Spam
• >>>
MongoDB operation
mongodb
PyMongo
mongo-java-driver
python
java
Install pymongo module
• How to install a third-party python module?
– easy_install pymongo
• Add C:Python27Scripts to windows environment path variables
– pip install pymongo
• wget https://pypi.python.org/packages/source/s/setuptools/setuptools-
1.1.tar.gz
• python setup.py install
• wget https://pypi.python.org/packages/source/p/pip/pip-1.4.1.tar.gz
• python setup.py install
– Installing from source
• $ git clone git://github.com/mongodb/mongo-python-driver.git pymongo
• $ cd pymongo/
• $ python setup.py install
pymongo
Thank you! Questions?

Más contenido relacionado

La actualidad más candente

Java Building Blocks
Java Building BlocksJava Building Blocks
Java Building BlocksCate Huston
 
GeekAustin PHP Class - Session 6
GeekAustin PHP Class - Session 6GeekAustin PHP Class - Session 6
GeekAustin PHP Class - Session 6jimbojsb
 
cpp-2013 #9 STL Algorithms Part 1
cpp-2013 #9 STL Algorithms Part 1cpp-2013 #9 STL Algorithms Part 1
cpp-2013 #9 STL Algorithms Part 1Amazon Web Services
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and ClassesMichael Heron
 
Introduction to programming with python
Introduction to programming with pythonIntroduction to programming with python
Introduction to programming with pythonPorimol Chandro
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascriptGarrison Locke
 
GDG Helwan Introduction to python
GDG Helwan Introduction to pythonGDG Helwan Introduction to python
GDG Helwan Introduction to pythonMohamed Hegazy
 
Concurrency & Parallel Programming
Concurrency & Parallel ProgrammingConcurrency & Parallel Programming
Concurrency & Parallel ProgrammingRamazan AYYILDIZ
 
Effective Scala: Programming Patterns
Effective Scala: Programming PatternsEffective Scala: Programming Patterns
Effective Scala: Programming PatternsVasil Remeniuk
 
Basics of python programming
Basics of python programmingBasics of python programming
Basics of python programmingAditi Bhushan
 
Typescript Fundamentals
Typescript FundamentalsTypescript Fundamentals
Typescript FundamentalsSunny Sharma
 
Test-Driven Development of Xtext DSLs
Test-Driven Development  of Xtext DSLsTest-Driven Development  of Xtext DSLs
Test-Driven Development of Xtext DSLsmeysholdt
 
Tuples, Dicts and Exception Handling
Tuples, Dicts and Exception HandlingTuples, Dicts and Exception Handling
Tuples, Dicts and Exception HandlingPranavSB
 
Getting started with typescript and angular 2
Getting started with typescript  and angular 2Getting started with typescript  and angular 2
Getting started with typescript and angular 2Knoldus Inc.
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional ProgrammingRyan Riley
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyBozhidar Bozhanov
 

La actualidad más candente (20)

Java Building Blocks
Java Building BlocksJava Building Blocks
Java Building Blocks
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
C Sharp Course 101.5
C Sharp Course 101.5C Sharp Course 101.5
C Sharp Course 101.5
 
GeekAustin PHP Class - Session 6
GeekAustin PHP Class - Session 6GeekAustin PHP Class - Session 6
GeekAustin PHP Class - Session 6
 
cpp-2013 #9 STL Algorithms Part 1
cpp-2013 #9 STL Algorithms Part 1cpp-2013 #9 STL Algorithms Part 1
cpp-2013 #9 STL Algorithms Part 1
 
TypeScript 101
TypeScript 101TypeScript 101
TypeScript 101
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and Classes
 
Introduction to programming with python
Introduction to programming with pythonIntroduction to programming with python
Introduction to programming with python
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascript
 
Java and the JVM
Java and the JVMJava and the JVM
Java and the JVM
 
GDG Helwan Introduction to python
GDG Helwan Introduction to pythonGDG Helwan Introduction to python
GDG Helwan Introduction to python
 
Concurrency & Parallel Programming
Concurrency & Parallel ProgrammingConcurrency & Parallel Programming
Concurrency & Parallel Programming
 
Effective Scala: Programming Patterns
Effective Scala: Programming PatternsEffective Scala: Programming Patterns
Effective Scala: Programming Patterns
 
Basics of python programming
Basics of python programmingBasics of python programming
Basics of python programming
 
Typescript Fundamentals
Typescript FundamentalsTypescript Fundamentals
Typescript Fundamentals
 
Test-Driven Development of Xtext DSLs
Test-Driven Development  of Xtext DSLsTest-Driven Development  of Xtext DSLs
Test-Driven Development of Xtext DSLs
 
Tuples, Dicts and Exception Handling
Tuples, Dicts and Exception HandlingTuples, Dicts and Exception Handling
Tuples, Dicts and Exception Handling
 
Getting started with typescript and angular 2
Getting started with typescript  and angular 2Getting started with typescript  and angular 2
Getting started with typescript and angular 2
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very ugly
 

Destacado

Indian Institute of Packaging celebrated inaugural function of Golden Jubilee...
Indian Institute of Packaging celebrated inaugural function of Golden Jubilee...Indian Institute of Packaging celebrated inaugural function of Golden Jubilee...
Indian Institute of Packaging celebrated inaugural function of Golden Jubilee...Suchita Panchal
 
Project report on polystyrene (ps)
Project report on polystyrene (ps)Project report on polystyrene (ps)
Project report on polystyrene (ps)Lanka Anil raj
 
Food Processing Brochure 060316[1]
Food Processing Brochure 060316[1]Food Processing Brochure 060316[1]
Food Processing Brochure 060316[1]omniumintl
 
Rian vebrianto brunai (PEMBANGUNAN MEDIA PENGAJARAN: MODUL DAN MULTIMEDIA DA...
Rian vebrianto  brunai (PEMBANGUNAN MEDIA PENGAJARAN: MODUL DAN MULTIMEDIA DA...Rian vebrianto  brunai (PEMBANGUNAN MEDIA PENGAJARAN: MODUL DAN MULTIMEDIA DA...
Rian vebrianto brunai (PEMBANGUNAN MEDIA PENGAJARAN: MODUL DAN MULTIMEDIA DA...Rian vebrianto
 
Ths general biology unit 1 our environment living relationships notes_v1516
Ths general biology unit 1 our environment living relationships notes_v1516Ths general biology unit 1 our environment living relationships notes_v1516
Ths general biology unit 1 our environment living relationships notes_v1516rozeka01
 
Why scala - executive overview
Why scala - executive overviewWhy scala - executive overview
Why scala - executive overviewRazvan Cojocaru
 
Combine may 2013 for web
Combine may 2013 for webCombine may 2013 for web
Combine may 2013 for webPUNJABI SUMAN
 
case study on bride burning
case study on bride burningcase study on bride burning
case study on bride burningPriyansha Gupta
 
Reading ppt
Reading pptReading ppt
Reading pptryfshs49
 
Poster the physiological effects of obesity on body system latest
Poster the physiological effects of obesity on body system latestPoster the physiological effects of obesity on body system latest
Poster the physiological effects of obesity on body system latestnur fara
 
Interoperability in a Highly Decentralised Country- Lessons Learned
Interoperability in a Highly Decentralised Country- Lessons LearnedInteroperability in a Highly Decentralised Country- Lessons Learned
Interoperability in a Highly Decentralised Country- Lessons LearnedPlan de Calidad para el SNS
 
Baiguullaga organition 2012
Baiguullaga organition 2012Baiguullaga organition 2012
Baiguullaga organition 2012oyundariubuns
 
The new masters of management
The new masters of managementThe new masters of management
The new masters of managementrsoosaar
 
Grm 201 project
Grm 201 projectGrm 201 project
Grm 201 projectnmjameson
 
ROR -Igal Assaf Paris sous la neige
ROR -Igal Assaf  Paris sous la neigeROR -Igal Assaf  Paris sous la neige
ROR -Igal Assaf Paris sous la neigeIgal Assaf
 

Destacado (20)

Indian Institute of Packaging celebrated inaugural function of Golden Jubilee...
Indian Institute of Packaging celebrated inaugural function of Golden Jubilee...Indian Institute of Packaging celebrated inaugural function of Golden Jubilee...
Indian Institute of Packaging celebrated inaugural function of Golden Jubilee...
 
A'NUE LIGNE
A'NUE LIGNE A'NUE LIGNE
A'NUE LIGNE
 
Project report on polystyrene (ps)
Project report on polystyrene (ps)Project report on polystyrene (ps)
Project report on polystyrene (ps)
 
Food Processing Brochure 060316[1]
Food Processing Brochure 060316[1]Food Processing Brochure 060316[1]
Food Processing Brochure 060316[1]
 
Rian vebrianto brunai (PEMBANGUNAN MEDIA PENGAJARAN: MODUL DAN MULTIMEDIA DA...
Rian vebrianto  brunai (PEMBANGUNAN MEDIA PENGAJARAN: MODUL DAN MULTIMEDIA DA...Rian vebrianto  brunai (PEMBANGUNAN MEDIA PENGAJARAN: MODUL DAN MULTIMEDIA DA...
Rian vebrianto brunai (PEMBANGUNAN MEDIA PENGAJARAN: MODUL DAN MULTIMEDIA DA...
 
Final Report
Final ReportFinal Report
Final Report
 
Ths general biology unit 1 our environment living relationships notes_v1516
Ths general biology unit 1 our environment living relationships notes_v1516Ths general biology unit 1 our environment living relationships notes_v1516
Ths general biology unit 1 our environment living relationships notes_v1516
 
Why scala - executive overview
Why scala - executive overviewWhy scala - executive overview
Why scala - executive overview
 
Combine may 2013 for web
Combine may 2013 for webCombine may 2013 for web
Combine may 2013 for web
 
sdfghjk
sdfghjksdfghjk
sdfghjk
 
case study on bride burning
case study on bride burningcase study on bride burning
case study on bride burning
 
Reading ppt
Reading pptReading ppt
Reading ppt
 
Poster the physiological effects of obesity on body system latest
Poster the physiological effects of obesity on body system latestPoster the physiological effects of obesity on body system latest
Poster the physiological effects of obesity on body system latest
 
OpenStack Havana Release
OpenStack Havana ReleaseOpenStack Havana Release
OpenStack Havana Release
 
Interoperability in a Highly Decentralised Country- Lessons Learned
Interoperability in a Highly Decentralised Country- Lessons LearnedInteroperability in a Highly Decentralised Country- Lessons Learned
Interoperability in a Highly Decentralised Country- Lessons Learned
 
Baiguullaga organition 2012
Baiguullaga organition 2012Baiguullaga organition 2012
Baiguullaga organition 2012
 
The new masters of management
The new masters of managementThe new masters of management
The new masters of management
 
Grm 201 project
Grm 201 projectGrm 201 project
Grm 201 project
 
Oppa (30)
Oppa (30)Oppa (30)
Oppa (30)
 
ROR -Igal Assaf Paris sous la neige
ROR -Igal Assaf  Paris sous la neigeROR -Igal Assaf  Paris sous la neige
ROR -Igal Assaf Paris sous la neige
 

Similar a Python introduction

web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh MalothBhavsingh Maloth
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonMohammed Rafi
 
pythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxpythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxRohitKumar639388
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programmingChetan Giridhar
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAdam Getchell
 
Python indroduction
Python indroductionPython indroduction
Python indroductionFEG
 
Travis Oliphant "Python for Speed, Scale, and Science"
Travis Oliphant "Python for Speed, Scale, and Science"Travis Oliphant "Python for Speed, Scale, and Science"
Travis Oliphant "Python for Speed, Scale, and Science"Fwdays
 
python presntation 2.pptx
python presntation 2.pptxpython presntation 2.pptx
python presntation 2.pptxArpittripathi45
 
Reproducibility and automation of machine learning process
Reproducibility and automation of machine learning processReproducibility and automation of machine learning process
Reproducibility and automation of machine learning processDenis Dus
 
Python-Yesterday Today Tomorrow(What's new?)
Python-Yesterday Today Tomorrow(What's new?)Python-Yesterday Today Tomorrow(What's new?)
Python-Yesterday Today Tomorrow(What's new?)Mohan Arumugam
 
Introduction To Python
Introduction To PythonIntroduction To Python
Introduction To PythonVanessa Rene
 
What is Python?
What is Python?What is Python?
What is Python?PranavSB
 
Standardizing arrays -- Microsoft Presentation
Standardizing arrays -- Microsoft PresentationStandardizing arrays -- Microsoft Presentation
Standardizing arrays -- Microsoft PresentationTravis Oliphant
 

Similar a Python introduction (20)

Python for dummies
Python for dummiesPython for dummies
Python for dummies
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Maloth
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python Demo.pptx
Python Demo.pptxPython Demo.pptx
Python Demo.pptx
 
pythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxpythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptx
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
 
Python indroduction
Python indroductionPython indroduction
Python indroduction
 
Python Demo.pptx
Python Demo.pptxPython Demo.pptx
Python Demo.pptx
 
Python training
Python trainingPython training
Python training
 
Travis Oliphant "Python for Speed, Scale, and Science"
Travis Oliphant "Python for Speed, Scale, and Science"Travis Oliphant "Python for Speed, Scale, and Science"
Travis Oliphant "Python for Speed, Scale, and Science"
 
python presntation 2.pptx
python presntation 2.pptxpython presntation 2.pptx
python presntation 2.pptx
 
Python made easy
Python made easy Python made easy
Python made easy
 
Python programming
Python programmingPython programming
Python programming
 
Reproducibility and automation of machine learning process
Reproducibility and automation of machine learning processReproducibility and automation of machine learning process
Reproducibility and automation of machine learning process
 
Python-Yesterday Today Tomorrow(What's new?)
Python-Yesterday Today Tomorrow(What's new?)Python-Yesterday Today Tomorrow(What's new?)
Python-Yesterday Today Tomorrow(What's new?)
 
Introduction To Python
Introduction To PythonIntroduction To Python
Introduction To Python
 
What is Python?
What is Python?What is Python?
What is Python?
 
Python
PythonPython
Python
 
Standardizing arrays -- Microsoft Presentation
Standardizing arrays -- Microsoft PresentationStandardizing arrays -- Microsoft Presentation
Standardizing arrays -- Microsoft Presentation
 

Más de Roger Xia

机器学习推动金融数据智能
机器学习推动金融数据智能机器学习推动金融数据智能
机器学习推动金融数据智能Roger Xia
 
Code reviews
Code reviewsCode reviews
Code reviewsRoger Xia
 
Learning notes ruby
Learning notes rubyLearning notes ruby
Learning notes rubyRoger Xia
 
Converged open platform for enterprise
Converged open platform for enterpriseConverged open platform for enterprise
Converged open platform for enterpriseRoger Xia
 
E commerce search strategies
E commerce search strategiesE commerce search strategies
E commerce search strategiesRoger Xia
 
Indefero source code_managment
Indefero source code_managmentIndefero source code_managment
Indefero source code_managmentRoger Xia
 
Web Services Atomic Transactio
 Web Services Atomic Transactio Web Services Atomic Transactio
Web Services Atomic TransactioRoger Xia
 
Web service through cxf
Web service through cxfWeb service through cxf
Web service through cxfRoger Xia
 
Q con london2011-matthewwall-whyichosemongodbforguardiancouk
Q con london2011-matthewwall-whyichosemongodbforguardiancoukQ con london2011-matthewwall-whyichosemongodbforguardiancouk
Q con london2011-matthewwall-whyichosemongodbforguardiancoukRoger Xia
 
Spring one2gx2010 spring-nonrelational_data
Spring one2gx2010 spring-nonrelational_dataSpring one2gx2010 spring-nonrelational_data
Spring one2gx2010 spring-nonrelational_dataRoger Xia
 
Consistency-New-Generation-Databases
Consistency-New-Generation-DatabasesConsistency-New-Generation-Databases
Consistency-New-Generation-DatabasesRoger Xia
 
Java explore
Java exploreJava explore
Java exploreRoger Xia
 
Mongo db实战
Mongo db实战Mongo db实战
Mongo db实战Roger Xia
 
Ca siteminder
Ca siteminderCa siteminder
Ca siteminderRoger Xia
 
Fixing twitter
Fixing twitterFixing twitter
Fixing twitterRoger Xia
 
Eclipse plug in mylyn & tasktop
Eclipse plug in mylyn & tasktopEclipse plug in mylyn & tasktop
Eclipse plug in mylyn & tasktopRoger Xia
 
新浪微博架构猜想
新浪微博架构猜想新浪微博架构猜想
新浪微博架构猜想Roger Xia
 
构建高效能的Web网站 精选版-by-infoq
构建高效能的Web网站 精选版-by-infoq构建高效能的Web网站 精选版-by-infoq
构建高效能的Web网站 精选版-by-infoqRoger Xia
 

Más de Roger Xia (20)

机器学习推动金融数据智能
机器学习推动金融数据智能机器学习推动金融数据智能
机器学习推动金融数据智能
 
Code reviews
Code reviewsCode reviews
Code reviews
 
Learning notes ruby
Learning notes rubyLearning notes ruby
Learning notes ruby
 
Converged open platform for enterprise
Converged open platform for enterpriseConverged open platform for enterprise
Converged open platform for enterprise
 
E commerce search strategies
E commerce search strategiesE commerce search strategies
E commerce search strategies
 
Saml
SamlSaml
Saml
 
JavaEE6
JavaEE6JavaEE6
JavaEE6
 
Indefero source code_managment
Indefero source code_managmentIndefero source code_managment
Indefero source code_managment
 
Web Services Atomic Transactio
 Web Services Atomic Transactio Web Services Atomic Transactio
Web Services Atomic Transactio
 
Web service through cxf
Web service through cxfWeb service through cxf
Web service through cxf
 
Q con london2011-matthewwall-whyichosemongodbforguardiancouk
Q con london2011-matthewwall-whyichosemongodbforguardiancoukQ con london2011-matthewwall-whyichosemongodbforguardiancouk
Q con london2011-matthewwall-whyichosemongodbforguardiancouk
 
Spring one2gx2010 spring-nonrelational_data
Spring one2gx2010 spring-nonrelational_dataSpring one2gx2010 spring-nonrelational_data
Spring one2gx2010 spring-nonrelational_data
 
Consistency-New-Generation-Databases
Consistency-New-Generation-DatabasesConsistency-New-Generation-Databases
Consistency-New-Generation-Databases
 
Java explore
Java exploreJava explore
Java explore
 
Mongo db实战
Mongo db实战Mongo db实战
Mongo db实战
 
Ca siteminder
Ca siteminderCa siteminder
Ca siteminder
 
Fixing twitter
Fixing twitterFixing twitter
Fixing twitter
 
Eclipse plug in mylyn & tasktop
Eclipse plug in mylyn & tasktopEclipse plug in mylyn & tasktop
Eclipse plug in mylyn & tasktop
 
新浪微博架构猜想
新浪微博架构猜想新浪微博架构猜想
新浪微博架构猜想
 
构建高效能的Web网站 精选版-by-infoq
构建高效能的Web网站 精选版-by-infoq构建高效能的Web网站 精选版-by-infoq
构建高效能的Web网站 精选版-by-infoq
 

Último

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Último (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Python introduction

  • 2. What is A dynamic object-oriented programming language. Python is a programming language that lets you work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs. – http://www.python.org/
  • 3. Zen
  • 5. Who is using Python? spider and search engine Yahoo Maps, Yahoo Groups Python Success Stories – http://www.python.org/about/success/ – Star Wars! : http://www.youtube.com/watch?v=RqhUz2vh6lA – http://lineofthought.com/tools/python
  • 6. My experience on Python? • 2007-2010 – Web Automation testing : MaxQ – Crawler web news for vertical search : beautifulsoup, lxml, mechanize • 2011 – Text/file processing – hadoop? • 2013 – scrapy (twisted) vs. gcrawler (gevent)
  • 7. What Python can do? • Xml processing • Web Application • Off-line computation • Operation scripts – puppet/chef(ruby) – salt(python) • NLP Processing – has strong numeric processing capability : matrix operations, etc – Suitable for probability and machine learning code. – NLTK : nature language tool kit
  • 8. • data analysis • machine learning • Big data : R: http://www.xmind.net/m/LKF2/
  • 9.
  • 10. Python has a simple, minimal, clean syntax
  • 11. find the roots of a quadratic equation
  • 13. Easy to get started! • http://www.python.org/doc/ • <<Dive into Python>> : http://www.diveintopython.net/toc/index.html • Python standard libraries: http://docs.python.org/2/library/index.html • Google • PyPI : http://pypi.python.org/pypi – There are currently 33961 packages • PyCon : http://www.pycon.org/ • Practice, practice, practice
  • 14. Getting started and Installation • Windows : find the install package here http://www.python.org/download/releases/2.7.5/ • Linux : Generally, python come installed with the operating system, if not, try – Centos/redhat : yum install python – Ubuntu : sudo apt-get install python2.7 – wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz (./configure & make & make install)
  • 15. Using the python interpreter • Indentation/缩进 • # • “”” (doc string) • Variables are created when they are assigned. The name is case sensitive. • If __name__==“__main__”: – __name__ is a built-in variable which evaluate to the name of the current module. – being run directly or being imported?
  • 16. Built-in types • None • bool : True/False • int/long/float • str/unicode (u’Spam’) • tuple • list • dict • lambda expression
  • 17. Dictionary • defines one-to-one relationships between keys and values /定义了键和值之间一对一的 关系
  • 18. List
  • 19. Using lists as stacks/queues
  • 20. List comprehensions creating a list based on existing lists Nested List comprehensions Built in function
  • 21. Tuple • A tuple is an immutable list. A tuple can not be changed in any way once it is created.
  • 22.
  • 23. Defining Functions >>> def fib(start=0, n=2000): ... "Print a Fibonacci series up to n, start from start" ... result = [] ... a, b = start, start+1 ... while b < n: ... result.append(b) ... a, b = b, a+b ... return result ... >>> f1 = fib(5) >>> f1 [6, 11, 17, 28, 45, 73, 118, 191, 309, 500, 809, 1309] >>> f2 = fib(0, 1000) >>> f2 [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]
  • 24. Lambda Functions anonymous functions in python Type help() for help documents Python 支持一种有趣的语法,它允许你快速定义单行的最小函数。这些叫做 lambda 的函数,是从 Lisp 借用来的,可以用在任何需要函数的地方。
  • 25. >>> a = ['Mary', 'had', 'a', 'little', 'lamb'] >>> for i in range(len(a)): ... print i, a[i] ... 0 Mary 1 had 2 a 3 little 4 lamb
  • 26. others • Regular expressions: – http://www.tutorialspoint.com/python/python_re g_expressions.htm • Exceptions: – http://docs.python.org/2/tutorial/errors.html
  • 27. Modules • A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Within a module, the module’s name is available as the value of the global variable __name__. – A module can contain executable statements as well as function definitions. These statements are intended to initialize the module. They are executed only the first time the module name is encountered in an import statement. – Each module has its own private symbol table, which is used as the global symbol table by all functions defined in the module. – When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path.
  • 28. Packages • Packages are a way of structuring Python's module namespace by using "dotted module names". • The __init__.py files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name
  • 29. What can you do with excel? • 1. read/write to normal csv file • 2. use csv module to do it • 3. pypi search for excel – http://www.simplistix.co.uk/presentations/python -excel.pdf
  • 30. • >>> import csv • >>> with open('D:/eggs.csv', 'wb') as csvfile: • ... spamwriter = csv.writer(csvfile, delimiter=' ', quotechar='|', quoting=cs • v.QUOTE_MINIMAL) • ... spamwriter.writerow(['Spam'] * 5 + ['Baked Beans']) • ... spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam']) • ... • >>> with open('D:/eggs.csv', 'rb') as csvfile: • ... spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|') • ... for row in spamreader: • ... print ', '.join(row) • ... • Spam, Spam, Spam, Spam, Spam, Baked Beans • Spam, Lovely Spam, Wonderful Spam • >>>
  • 32. Install pymongo module • How to install a third-party python module? – easy_install pymongo • Add C:Python27Scripts to windows environment path variables – pip install pymongo • wget https://pypi.python.org/packages/source/s/setuptools/setuptools- 1.1.tar.gz • python setup.py install • wget https://pypi.python.org/packages/source/p/pip/pip-1.4.1.tar.gz • python setup.py install – Installing from source • $ git clone git://github.com/mongodb/mongo-python-driver.git pymongo • $ cd pymongo/ • $ python setup.py install

Notas del editor

  1. Code is 2-10x shorter than C, C++, JavaCode is extremely readableLanguage is very easy to learn
  2. http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
  3. http://stackoverflow.com/questions/12267544/machine-translation-using-babelize-shell-in-nltk
  4. http://bitworking.org/news/Why_so_many_Python_web_frameworksR(又称R语言)是一款开源的跨平台的数值统计和数值图形化展现工具。通俗点说,R是用来做统计和画图的。R拥有自己的脚本语言和大量的统计、图形库(得益于开源社区),这让她看起来既美又实用。http://www.r-bloggers.com/stepping-up-to-big-data-with-r-and-python-a-mind-map-of-all-the-packages-you-will-ever-need/http://it-ebooks.info/book/1041/https://speakerdeck.com/pyconslides/awesome-big-data-algorithms-by-titus-brownhttps://speakerdeck.com/pyconslides/building-an-image-processing-pipeline-with-python-by-franck-chastagnol
  5. http://www.xmind.net/m/WvfC/
  6. http://folk.uio.no/hpl/WhyPython.pdf
  7. Pyrex : http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/http://www.objectsbydesign.com/projects/python_links.html
  8. Add C:\Python27 to windows path to run python under cmd
  9. http://docs.python.org/2/library/types.html
  10. Using lists as stacks/queues
  11. It is also possible to use a list as a queue, where the first element added is the first element retrieved (“first-in, first-out”); however, lists are not efficient for this purpose. While appends and pops from the end of list are fast, doing inserts or pops from the beginning of a list is slow (because all of the other elements have to be shifted by one).To implement a queue, use collections.deque which was designed to have fast appends and pops from both ends.
  12. It is also possible to use a list as a queue, where the first element added is the first element retrieved (“first-in, first-out”); however, lists are not efficient for this purpose. While appends and pops from the end of list are fast, doing inserts or pops from the beginning of a list is slow (because all of the other elements have to be shifted by one).To implement a queue, use collections.deque which was designed to have fast appends and pops from both ends.
  13. Tuple 比 list 操作速度快。如果您定义了一个值的常量集,并且唯一要用它做的是不断地遍历它,请使用 tuple 代替 list。如果对不需要修改的数据进行 “写保护”,可以使代码更安全。Tuples 可以在 dictionary 中被用做 key,但是 list 不行。Dictionary key 必须是不可变的。Tuple 本身是不可改变的,但是如果您有一个 list 的 tuple,那就认为是可变的了,用做 dictionary key 就是不安全的。只有字符串、整数或其它对 dictionary 安全的 tuple 才可以用作 dictionary key。
  14. all variable assignments in a function store the value in the local symbol table; whereas variable references first look in the local symbol table, then in the global symbol table, and then in the table of built-in names.
  15. map(...) map(function, sequence[, sequence, ...]) -&gt; list Return a list of the results of applying the function to the items of the argument sequence(s). If more than one sequence is given, the function is called with an argument list consisting of the corresponding item of each sequence, substituting None for missing values when not all sequences have the same length. If the function is None, return a list of the items of the sequence (or a list of tuples if more than one sequence).reduce(...) reduce(function, sequence[, initial]) -&gt; value Apply a function of two arguments cumulatively to the items of a sequence, from left to right, so as to reduce the sequence to a single value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates ((((1+2)+3)+4)+5). If initial is present, it is placed before the items of the sequence in the calculation, and serves as a default when the sequence is empty.
  16. http://docs.python.org/2/library/functions.html
  17. http://docs.python.org/2/tutorial/modules.htmlIf you quit from the Python interpreter and enter it again, the definitions you have made (functions and variables) are lost. Therefore, if you want to write a somewhat longer program, you are better off using a text editor to prepare the input for the interpreter and running it with that file as input instead. This is known as creating a script. As your program gets longer, you may want to split it into several files for easier maintenance. You may also want to use a handy function that you’ve written in several programs without copying its definition into each program.Python has a way to put definitions in a file and use them in a script or in an interactive instance of the interpreter. Such a file is called a module; definitions from a module can be imported into other modules or into the main module
  18. The csv module implements classes to read and write tabular data in CSV format.http://docs.python.org/2/library/csv.html
  19. http://docs.mongodb.org/ecosystem/drivers/python/
  20. http://api.mongodb.org/python/current/installation.html
  21. http://api.mongodb.org/python/current/tutorial.htmlhttp://api.mongodb.org/python/current/api/index.htmlhttps://education.10gen.com/courses/10gen/M101P/2013_September/about