SlideShare a Scribd company logo
1 of 15
Download to read 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/

More Related Content

What's hot

Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1
Kanchilug
 

What's hot (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
 

Similar to Python for the Mobile and Web

Gnana Prasuna B_5.5 years
Gnana Prasuna B_5.5 yearsGnana Prasuna B_5.5 years
Gnana Prasuna B_5.5 years
Gnana Bocha
 
IITI Hub BTP Report
IITI Hub BTP ReportIITI Hub BTP Report
IITI Hub BTP Report
harshit4003
 
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
Sam Basu
 
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
Rachel Jaro
 

Similar to 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
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

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/