SlideShare uma empresa Scribd logo
1 de 15
Baixar para ler offline
© 2013 NUS. The contents contained in this document may not be reproduced in any form or by any means, without the written permission of ISS, NUS other than for the purpose for which it has been supplied.
Software Development
Python for Mobile and Web
Total: 15 pagesATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0
Derek Kiong
dkiong@nus.edu.sg
© 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 2
What is Python?
Small and consistent programming language
Supports multiple programming paradigms –
object-oriented, imperative and functional
Design philosophy emphasizes code
readability – has clear syntax
has comprehensive standard library
latent (dynamic) type system
run-time model similar to Scheme/Lisp
© 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 3
Python Features
Dynamic typing – does not require
declaration
Contrast C and Java which have strong typing
(implemented through compile-time checks)
Dynamic objects with built-in memory
management
Similar with Java and C#
Contrast C and C++
Even function definition is dynamic
© 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 4
Python Language Features
int, float, complex, bool, str, bytes
list, tuple, set, dict
control flow statements, iterator, generator,
exception handling
functions, parameters
class, object, lambda
extensive function/class libraries
kivy and django are Python modules
© 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 5
Python Sample
def factorial(n):
if n > 1:
return n*factorial(n-1)
else:
return 1
def list(n):
for i in range(n):
if i%2 == 0:
print "{0} is even".format(i)
else:
print "{0} is odd".format(i)
© 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 6
Python Sample
def factorial2(n):
result = 1
for i in range(n,0,-1):
result = result*i
return result
def myadd(a,b):
"""
Adds a and b using + operator
"""
return a+b
© 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 7
Android phone/tablet
app = androidhelper.Android()
app.dialogCreateSpinnerProgress("Coffee", "checking...")
app.dialogShow()
pg = urlopen("http://www.beans-r-us.biz/prices.html")
text = pg.read().decode("utf8")
m = re.search(r'>$([.d]+)<',text)
if m:
price = float(m.group(1))
else:
price = 0
app.dialogDismiss()
app.vibrate()
© 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 8
Android phone/tablet
app.dialogCreateAlert("Current price of coffee beans:")
app.dialogSetItems([price])
app.dialogSetPositiveButtonText('OK')
app.dialogShow()
resp = app.dialogGetResponse().result
app.makeToast("Bye!")
© 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 9
Django for the Web
Model-View-Controller (MVC) Web
framework
Object-relational mapping
Generated admin pages
URL driven site
Templating system
© 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 10
Django Model
Model specified in Python
from django.db import models
class Product(models.Model):
code = models.CharField(max_length=8)
description = models.CharField(max_length=22)
price = models.IntegerField()
def __str__(self):
return self.description
class Admin: pass
© 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 11
URL matching
import mysite.inventory.views
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'mysite.views.home', name='home'),
# url(r'^mysite/', include('mysite.foo.urls')),
url(r'^product/?$', mysite.inventory.views.productlisting),
url(r'^product/(.+)$', mysite.inventory.views.product),
)
© 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 12
Views
from mysite.inventory.models import Product
def productlisting(request):
list = Product.objects.all()
t = get_template('productlisting.html')
html = t.render(Context({'products':list}))
return HttpResponse(html)
def product(request, pcode):
p = Product.objects.get(code=pcode)
t = get_template('product.html')
html = t.render(Context({'product':p}))
return HttpResponse(html)
© 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 13
productlisting.html template
<html><body>
<h1>Products</h1>
<ul>
{% for p in products %}
<li>
<a href="/product/{{ p.code }}">
{{ p.code }}
</a>
</li>
{% endfor %}
</ul>
</body></html>
© 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 14
product.html template
<html><body>
<h1>Product Information</h1>
<table border="1" style="solid">
<tr>
<th>Code</th>
<th>Description</th>
<th>Price</th>
</tr>
<tr>
<td> {{ product.code }} </td>
<td> {{ product.description }} </td>
<td> {{ product.price }} </td>
</tr>
</table>
</body></html>
© 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 15
Summary
Python late binding provides much flexibility
http://docs.python.org/2/reference/
QPython in Android
http://qpython.com/
Django for the Web
https://docs.djangoproject.com/en/1.5/

Mais conteúdo relacionado

Mais procurados

Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An IntroductionSwarit Wadhe
 
1901200100000 presentation short term mini project on python
1901200100000 presentation short term mini project on python1901200100000 presentation short term mini project on python
1901200100000 presentation short term mini project on pythonSANTOSHJAISWAL52
 
Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1Kanchilug
 
summer training report on python
summer training report on pythonsummer training report on python
summer training report on pythonShubham Yadav
 
Introduction To Python
Introduction To PythonIntroduction To Python
Introduction To PythonVanessa Rene
 
Python presentation by Monu Sharma
Python presentation by Monu SharmaPython presentation by Monu Sharma
Python presentation by Monu SharmaMayank Sharma
 
Python in real world.
Python in real world.Python in real world.
Python in real world.Alph@.M
 
PYTHON CURRENT TREND APPLICATIONS- AN OVERVIEW
PYTHON CURRENT TREND APPLICATIONS- AN OVERVIEWPYTHON CURRENT TREND APPLICATIONS- AN OVERVIEW
PYTHON CURRENT TREND APPLICATIONS- AN OVERVIEWEditorIJAERD
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonManishJha237
 
Why Python?
Why Python?Why Python?
Why Python?Adam Pah
 
Presentation on python
Presentation on pythonPresentation on python
Presentation on pythonwilliam john
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialQA TrainingHub
 
11 Unit1 Chapter 1 Getting Started With Python
11   Unit1 Chapter 1 Getting Started With Python11   Unit1 Chapter 1 Getting Started With Python
11 Unit1 Chapter 1 Getting Started With PythonPraveen M Jigajinni
 
Python Summer Internship
Python Summer InternshipPython Summer Internship
Python Summer InternshipAtul Kumar
 
Python Programming ppt
Python Programming pptPython Programming ppt
Python Programming pptismailmrribi
 
Python presentation
Python presentationPython presentation
Python presentationgaganapponix
 

Mais procurados (19)

Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
 
1901200100000 presentation short term mini project on python
1901200100000 presentation short term mini project on python1901200100000 presentation short term mini project on python
1901200100000 presentation short term mini project on python
 
Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1
 
summer training report on python
summer training report on pythonsummer training report on python
summer training report on python
 
Introduction to python
 Introduction to python Introduction to python
Introduction to python
 
Introduction To Python
Introduction To PythonIntroduction To Python
Introduction To Python
 
Python presentation by Monu Sharma
Python presentation by Monu SharmaPython presentation by Monu Sharma
Python presentation by Monu Sharma
 
Python in real world.
Python in real world.Python in real world.
Python in real world.
 
PYTHON CURRENT TREND APPLICATIONS- AN OVERVIEW
PYTHON CURRENT TREND APPLICATIONS- AN OVERVIEWPYTHON CURRENT TREND APPLICATIONS- AN OVERVIEW
PYTHON CURRENT TREND APPLICATIONS- AN OVERVIEW
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Why Python?
Why Python?Why Python?
Why Python?
 
Presentation on python
Presentation on pythonPresentation on python
Presentation on python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python Tutorial
 
11 Unit1 Chapter 1 Getting Started With Python
11   Unit1 Chapter 1 Getting Started With Python11   Unit1 Chapter 1 Getting Started With Python
11 Unit1 Chapter 1 Getting Started With Python
 
Python Summer Internship
Python Summer InternshipPython Summer Internship
Python Summer Internship
 
Python Programming ppt
Python Programming pptPython Programming ppt
Python Programming ppt
 
Python presentation
Python presentationPython presentation
Python presentation
 
Python
PythonPython
Python
 

Semelhante a Python for the Mobile and Web

ICT, Importance of programming and programming languages
ICT, Importance of programming and programming languagesICT, Importance of programming and programming languages
ICT, Importance of programming and programming languagesEbin Robinson
 
Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...
Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...
Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...DicodingEvent
 
Gnana Prasuna B_5.5 years
Gnana Prasuna B_5.5 yearsGnana Prasuna B_5.5 years
Gnana Prasuna B_5.5 yearsGnana Bocha
 
IITI Hub BTP Report
IITI Hub BTP ReportIITI Hub BTP Report
IITI Hub BTP Reportharshit4003
 
Windows Phone 7.5 Mango - What's New
Windows Phone 7.5 Mango - What's NewWindows Phone 7.5 Mango - What's New
Windows Phone 7.5 Mango - What's NewSascha Corti
 
JQuery Mobile vs Appcelerator Titanium vs Sencha Touch
JQuery Mobile vs Appcelerator Titanium vs Sencha TouchJQuery Mobile vs Appcelerator Titanium vs Sencha Touch
JQuery Mobile vs Appcelerator Titanium vs Sencha TouchSteve Drucker
 
Java Swing vs. Android App
Java Swing vs. Android AppJava Swing vs. Android App
Java Swing vs. Android AppJohnny Hujol
 
Samsung SDS OpeniT - The possibility of Python
Samsung SDS OpeniT - The possibility of PythonSamsung SDS OpeniT - The possibility of Python
Samsung SDS OpeniT - The possibility of PythonInsuk (Chris) Cho
 
DSC IIITL Flutter Workshop
DSC IIITL Flutter WorkshopDSC IIITL Flutter Workshop
DSC IIITL Flutter WorkshopDSCIIITLucknow
 
PHP in a mobile ecosystem
PHP in a mobile ecosystem PHP in a mobile ecosystem
PHP in a mobile ecosystem Ivo Jansch
 
Packaging Automation Best Practices for InduSoft Web Studio
Packaging Automation Best Practices for InduSoft Web StudioPackaging Automation Best Practices for InduSoft Web Studio
Packaging Automation Best Practices for InduSoft Web StudioAVEVA
 
What's New with Windows Phone - FoxCon Talk
What's New with Windows Phone - FoxCon TalkWhat's New with Windows Phone - FoxCon Talk
What's New with Windows Phone - FoxCon TalkSam Basu
 
AnDevCon: Introduction to Darwino
AnDevCon: Introduction to DarwinoAnDevCon: Introduction to Darwino
AnDevCon: Introduction to DarwinoPhilippe Riand
 
Drupal as a Framework for Mobile Development
Drupal as a Framework for Mobile DevelopmentDrupal as a Framework for Mobile Development
Drupal as a Framework for Mobile DevelopmentRachel Jaro
 

Semelhante a Python for the Mobile and Web (20)

CV - Jaspreet Singh
CV - Jaspreet SinghCV - Jaspreet Singh
CV - Jaspreet Singh
 
ICT, Importance of programming and programming languages
ICT, Importance of programming and programming languagesICT, Importance of programming and programming languages
ICT, Importance of programming and programming languages
 
Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...
Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...
Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...
 
Gnana Prasuna B_5.5 years
Gnana Prasuna B_5.5 yearsGnana Prasuna B_5.5 years
Gnana Prasuna B_5.5 years
 
Android Starter Kit
Android Starter KitAndroid Starter Kit
Android Starter Kit
 
IITI Hub BTP Report
IITI Hub BTP ReportIITI Hub BTP Report
IITI Hub BTP Report
 
Windows Phone 7.5 Mango - What's New
Windows Phone 7.5 Mango - What's NewWindows Phone 7.5 Mango - What's New
Windows Phone 7.5 Mango - What's New
 
JQuery Mobile vs Appcelerator Titanium vs Sencha Touch
JQuery Mobile vs Appcelerator Titanium vs Sencha TouchJQuery Mobile vs Appcelerator Titanium vs Sencha Touch
JQuery Mobile vs Appcelerator Titanium vs Sencha Touch
 
Java Swing vs. Android App
Java Swing vs. Android AppJava Swing vs. Android App
Java Swing vs. Android App
 
Ramesh iOS Profile
Ramesh iOS ProfileRamesh iOS Profile
Ramesh iOS Profile
 
Android TCJUG
Android TCJUGAndroid TCJUG
Android TCJUG
 
Samsung SDS OpeniT - The possibility of Python
Samsung SDS OpeniT - The possibility of PythonSamsung SDS OpeniT - The possibility of Python
Samsung SDS OpeniT - The possibility of Python
 
DSC IIITL Flutter Workshop
DSC IIITL Flutter WorkshopDSC IIITL Flutter Workshop
DSC IIITL Flutter Workshop
 
PraveenResume_4+
PraveenResume_4+PraveenResume_4+
PraveenResume_4+
 
PHP in a mobile ecosystem
PHP in a mobile ecosystem PHP in a mobile ecosystem
PHP in a mobile ecosystem
 
python.pptx
python.pptxpython.pptx
python.pptx
 
Packaging Automation Best Practices for InduSoft Web Studio
Packaging Automation Best Practices for InduSoft Web StudioPackaging Automation Best Practices for InduSoft Web Studio
Packaging Automation Best Practices for InduSoft Web Studio
 
What's New with Windows Phone - FoxCon Talk
What's New with Windows Phone - FoxCon TalkWhat's New with Windows Phone - FoxCon Talk
What's New with Windows Phone - FoxCon Talk
 
AnDevCon: Introduction to Darwino
AnDevCon: Introduction to DarwinoAnDevCon: Introduction to Darwino
AnDevCon: Introduction to Darwino
 
Drupal as a Framework for Mobile Development
Drupal as a Framework for Mobile DevelopmentDrupal as a Framework for Mobile Development
Drupal as a Framework for Mobile Development
 

Último

Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 

Python for the Mobile and Web

  • 1. © 2013 NUS. The contents contained in this document may not be reproduced in any form or by any means, without the written permission of ISS, NUS other than for the purpose for which it has been supplied. Software Development Python for Mobile and Web Total: 15 pagesATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Derek Kiong dkiong@nus.edu.sg
  • 2. © 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 2 What is Python? Small and consistent programming language Supports multiple programming paradigms – object-oriented, imperative and functional Design philosophy emphasizes code readability – has clear syntax has comprehensive standard library latent (dynamic) type system run-time model similar to Scheme/Lisp
  • 3. © 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 3 Python Features Dynamic typing – does not require declaration Contrast C and Java which have strong typing (implemented through compile-time checks) Dynamic objects with built-in memory management Similar with Java and C# Contrast C and C++ Even function definition is dynamic
  • 4. © 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 4 Python Language Features int, float, complex, bool, str, bytes list, tuple, set, dict control flow statements, iterator, generator, exception handling functions, parameters class, object, lambda extensive function/class libraries kivy and django are Python modules
  • 5. © 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 5 Python Sample def factorial(n): if n > 1: return n*factorial(n-1) else: return 1 def list(n): for i in range(n): if i%2 == 0: print "{0} is even".format(i) else: print "{0} is odd".format(i)
  • 6. © 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 6 Python Sample def factorial2(n): result = 1 for i in range(n,0,-1): result = result*i return result def myadd(a,b): """ Adds a and b using + operator """ return a+b
  • 7. © 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 7 Android phone/tablet app = androidhelper.Android() app.dialogCreateSpinnerProgress("Coffee", "checking...") app.dialogShow() pg = urlopen("http://www.beans-r-us.biz/prices.html") text = pg.read().decode("utf8") m = re.search(r'>$([.d]+)<',text) if m: price = float(m.group(1)) else: price = 0 app.dialogDismiss() app.vibrate()
  • 8. © 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 8 Android phone/tablet app.dialogCreateAlert("Current price of coffee beans:") app.dialogSetItems([price]) app.dialogSetPositiveButtonText('OK') app.dialogShow() resp = app.dialogGetResponse().result app.makeToast("Bye!")
  • 9. © 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 9 Django for the Web Model-View-Controller (MVC) Web framework Object-relational mapping Generated admin pages URL driven site Templating system
  • 10. © 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 10 Django Model Model specified in Python from django.db import models class Product(models.Model): code = models.CharField(max_length=8) description = models.CharField(max_length=22) price = models.IntegerField() def __str__(self): return self.description class Admin: pass
  • 11. © 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 11 URL matching import mysite.inventory.views urlpatterns = patterns('', # Examples: # url(r'^$', 'mysite.views.home', name='home'), # url(r'^mysite/', include('mysite.foo.urls')), url(r'^product/?$', mysite.inventory.views.productlisting), url(r'^product/(.+)$', mysite.inventory.views.product), )
  • 12. © 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 12 Views from mysite.inventory.models import Product def productlisting(request): list = Product.objects.all() t = get_template('productlisting.html') html = t.render(Context({'products':list})) return HttpResponse(html) def product(request, pcode): p = Product.objects.get(code=pcode) t = get_template('product.html') html = t.render(Context({'product':p})) return HttpResponse(html)
  • 13. © 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 13 productlisting.html template <html><body> <h1>Products</h1> <ul> {% for p in products %} <li> <a href="/product/{{ p.code }}"> {{ p.code }} </a> </li> {% endfor %} </ul> </body></html>
  • 14. © 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 14 product.html template <html><body> <h1>Product Information</h1> <table border="1" style="solid"> <tr> <th>Code</th> <th>Description</th> <th>Price</th> </tr> <tr> <td> {{ product.code }} </td> <td> {{ product.description }} </td> <td> {{ product.price }} </td> </tr> </table> </body></html>
  • 15. © 2013 NUS. All rights reserved.ATA/SA-DIP/TUS/Python Mobile and Web.ppt/v1.0 Python for Mobile and Web 15 Summary Python late binding provides much flexibility http://docs.python.org/2/reference/ QPython in Android http://qpython.com/ Django for the Web https://docs.djangoproject.com/en/1.5/