SlideShare a Scribd company logo
1 of 51
Download to read offline
Creating Big Data:
Introduction to Python
Moshe Kaplan
moshe.kaplan@brightaqua.com
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Moshe Kaplan
> Scale Hacker:
Architecture (Sys and Data)
R&D
Solving Problems
> Blogs:
http://top-performance.blogspot.com
http://blogs.microsoft.co.il/vprnd
2
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
About Me: It’s all About Scale
3
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
INTRODUCTION
Background
4
http://geekandpoke.typepad.com/geekandpoke/2008/07/one-day-in-the.html
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Wny Python?
Simple and readable
Indentation: hard to mess
OOP and functional
Dynamic and auto memory management
Can be packaged
Cross platform
Wide number of libraries
Works great w/ Java, C, .Net
5
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Who is Behind?
Python Software Foundation
~1M USD annual budget
Created at 1989
Top 10 from 2008
6
https://en.wikipedia.org/wiki/Python_(programming_language)
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Who is Using?
7
http://www.dhruvb.com/blog/images/slides/python/using-python.png
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Python Version
2.X  Existing Projects
3.X  New Projects
Not so backwards compatible
8
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Materials
9
https://www.tocode.co.il
10% Discount
Coupon Code: PyApplied
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
IDEs
You can use Notepad++
10
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
HELLO WORLD
Background
11
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
12
http://www.dhruvb.com/blog/presentations/python/#/2
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
13
http://www.dhruvb.com/blog/presentations/python/#/2
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
VARIABLES, NUMBERS AND
STRINGS
Python
14
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
C:>Python
Type "help", "copyright", "credits" or "license" for more
information.
>>> a = "hello"
>>> print(a)
hello
>>> print(type(a))
<class 'str'>
>>> a = 1
>>> print(type(a))
<class 'int'>
>>>
Variables
15
Auto Declaration
Auto type assignment
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Numbers
Integer (int)
Floating
Complex (a+ib)
16
http://www.slideshare.net/TahaniAlManie/python-3-programming-language
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Strings
Immutable (cannot modify)
Char is a single char string
Starts w/ 0 and support –N
17
>>> a = "hello"
>>> a[0]
'h'
>>> a[-1]
'o'
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Strings Methods
18
http://www.slideshare.net/TahaniAlManie/python-3-programming-language
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Strings Operators
19
http://www.slideshare.net/TahaniAlManie/python-3-programming-language
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
LISTS AND TUPLES
Python
20
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Lists Basics
Mutable
Support multi types
Again 0–N
21
>>> l = [1, 'b', 'ccc']
>>> print(l[0])
1
>>> print(l[1:2]);
['b']
>>> l[2] = 3
>>> print(l)
>>> del(l[0])
>>> print(l)
['b', 3]
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Lists Magic
Supports list in a list
For each:
22
>>> a = [1, 2, 3]
>>> [x ** 2 for x in a]
[1, 4, 9]
http://www.slideshare.net/TahaniAlManie/python-3-programming-language
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Tuples
Similar functionality to lists
Immutable (cannot modify)
Faster than lists
Perfect for functional programming
23
>>> t = (1, 'b', 'ccc')
>>> t[0] = 2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Dictionaries Basics
Key/Value pairs (JSON like)
Mutable (cannot modify)
24
>>> d = {'name':'moshe', 'course':'PySpark'}
>>> print(d['name'])
moshe
>>> print(d.keys())
dict_keys(['name', 'course'])
>>> print(d.values())
dict_values(['moshe', 'PySpark'])
>>> print(d.items())
dict_items([('name', 'moshe'), ('course', 'PySpark')])
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Dictionaries Methods
25
http://www.slideshare.net/TahaniAlManie/python-3-programming-language
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
FUNCTIONS
Python
26
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Functions Basics
Flexible parameters:
27
>>> def a(name = "moshe", course = "pycourse"):
... print(name + ": " + course)
...
>>> a()
moshe: pycourse
>>> a("roni")
roni: pycourse
>>> a(course = "spark")
moshe: spark
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Variable Length Parameters and Refs
Not ByVal and not ByRef:
Mutuable: Object Reference (array)
Immutable: Change pointer each time (string)
28
>>> def f(*tup):
... for t in tup:
... print(t)
...
>>>
>>>
>>> f(1, "b", "ccc")
1
b
ccc
is vs ==
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
IF STATEMENTS AND LOOPS
Python
29
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
if
True or False conditions (no null)
Non Null  True
Non Zero  True
30
>>> b = True
>>> if b:
... print(1)
... elif b != True:
... print(2)
... else:
... print(3)
1
>>> x = 'correct' if b == True else 'wrong'
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
For Loops: Strings
31
>>> for letter in 'python':
... print(letter)
p
y
t
h
o
n
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
For Loops: For Each
32
>>> for x in range(1, 5):
... print(x)
...
1
2
3
4
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
While
continue: Well, continue
break: Well, break
pass: Void, due to indentation
33
>>> while (x < 5):
... print(x)
... x = x + 1
0
1
2
3
4
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
INPUT AND
BASIC TERMINAL APPS
Python
34
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Files
f = open(“file_name” [, access_mode] [,buffering])
“r”  read
“w”  recreate
“a”  append
“b”  add for binary reading
i = f.read()  All at once
line = f.readline()  Single line
lines = f.readlines()  All at once to a list
f.write(string)
f.close()
35
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
I/O
Immutable (cannot modify)
Char is a single char string
Starts w/ 0 and support –N
36
shuffelBlocks = (raw_input("Shuffel Blocks (y/n): ") == 'y')
print(shuffelBlocks)
assert(type(a) == type(1))
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
CLASSES AND ENTERPRISE
LEVEL PROGRAMMING
Python
37
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Classes
38
> Python class.py
Moshe is earning too much
Roni is earning 100
Total Employees: 2
Static variable
Constructor
Object var
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Inheritance
By default  Everything public
__attribute  Turn to private
Reflection++:
Multiple inheritance is supported
39
class shape:
...
class Circle(shape):
...
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Modules and Imports
Use 3rd party code:
Functions
Classes
Attributes
40
>>> import module1 [, module2]
>>> from module3 import name1 [, name2]
Only specific attributes
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Creating Modules
Simple header
And we are done…
41
"""file my_module.py
Module 'my_module': my special module
"""
def my_func(a):
if __name__ == '__main__':
print my_func(1)
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Packaging
42
def is_number(s):
try:
int(s)
return True
except ValueError:
return False
if __name__ == '__main__':
COLOR_BREAK = 'blue'
COLOR_HEADER_FOOTER = 'darkCyan';
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Python Compiler
See also .pyc file in your stack
43
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Python Integration
44
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
EXCEPTIONS
Python
45
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Try and Except
Common:
NameError
TypeError
IndexError
KeyError
46
try:
print(getattr(moshe, "course"))
except NameError:
print("no attribute1")
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
TESTING
Python
47
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
How to Do that?
48
import my_module
import unittest
class my_module_test(unittest.TestCase):
def test_method1(self):
self.assertFalse(method1(1))
if __name__ == '__main__':
unittest.main()
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
PREPARE FOR SPARK
Python
49
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Functions are Objects
50
# Evil Code…
>> log, exp = exp, log
>> r = [ -1, 0, 1]
>> map(abs, r)
[1, 0, 1]
>> def sum(x, y): return x+y
>> reduce(sum, r)
0
>> def large(x): return x > 0
>> filter(large, r)
[1]
© All rights reserved: Moshe Kaplan
http://top-performance.blogspot.com
Thank You !
Moshe Kaplan
moshe.kaplan@brightaqua.com
054-2291978

More Related Content

What's hot

Web Systems Architecture by Moshe Kaplan
Web Systems Architecture by Moshe KaplanWeb Systems Architecture by Moshe Kaplan
Web Systems Architecture by Moshe KaplanMoshe Kaplan
 
Optimizely Developer Showcase
Optimizely Developer ShowcaseOptimizely Developer Showcase
Optimizely Developer ShowcaseOptimizely
 
TechEvent Advanced Service Worker / PWA with Google Workbox
TechEvent Advanced Service Worker / PWA with Google WorkboxTechEvent Advanced Service Worker / PWA with Google Workbox
TechEvent Advanced Service Worker / PWA with Google WorkboxTrivadis
 
Scale and Cloud Design Patterns
Scale and Cloud Design PatternsScale and Cloud Design Patterns
Scale and Cloud Design PatternsMoshe Kaplan
 
Web Unleashed '19 - Measuring the Adoption of Web Performance Techniques
Web Unleashed '19 - Measuring the Adoption of Web Performance TechniquesWeb Unleashed '19 - Measuring the Adoption of Web Performance Techniques
Web Unleashed '19 - Measuring the Adoption of Web Performance TechniquesPaul Calvano
 
Staying in the fast lane - tools to keep your site speedy and light
Staying in the fast lane - tools to keep your site speedy and lightStaying in the fast lane - tools to keep your site speedy and light
Staying in the fast lane - tools to keep your site speedy and lightstefanjudis
 
Bespoke Software Development UK
Bespoke Software Development UKBespoke Software Development UK
Bespoke Software Development UKNathan Wynne
 

What's hot (9)

Web Systems Architecture by Moshe Kaplan
Web Systems Architecture by Moshe KaplanWeb Systems Architecture by Moshe Kaplan
Web Systems Architecture by Moshe Kaplan
 
Optimizely Developer Showcase
Optimizely Developer ShowcaseOptimizely Developer Showcase
Optimizely Developer Showcase
 
TechEvent Advanced Service Worker / PWA with Google Workbox
TechEvent Advanced Service Worker / PWA with Google WorkboxTechEvent Advanced Service Worker / PWA with Google Workbox
TechEvent Advanced Service Worker / PWA with Google Workbox
 
Scale and Cloud Design Patterns
Scale and Cloud Design PatternsScale and Cloud Design Patterns
Scale and Cloud Design Patterns
 
Web Unleashed '19 - Measuring the Adoption of Web Performance Techniques
Web Unleashed '19 - Measuring the Adoption of Web Performance TechniquesWeb Unleashed '19 - Measuring the Adoption of Web Performance Techniques
Web Unleashed '19 - Measuring the Adoption of Web Performance Techniques
 
Staying in the fast lane - tools to keep your site speedy and light
Staying in the fast lane - tools to keep your site speedy and lightStaying in the fast lane - tools to keep your site speedy and light
Staying in the fast lane - tools to keep your site speedy and light
 
Velocity Report 2009
Velocity Report 2009Velocity Report 2009
Velocity Report 2009
 
Bespoke Software Development UK
Bespoke Software Development UKBespoke Software Development UK
Bespoke Software Development UK
 
Hackference
HackferenceHackference
Hackference
 

Viewers also liked

Operational Excellence & Mobile
Operational Excellence & MobileOperational Excellence & Mobile
Operational Excellence & MobileUnvired Inc.
 
Big Data, Analytics & its impact on asset management
Big Data, Analytics & its impact on asset managementBig Data, Analytics & its impact on asset management
Big Data, Analytics & its impact on asset managementJohn Wentzel
 
BIG Data and Methodology-A review
BIG Data and Methodology-A reviewBIG Data and Methodology-A review
BIG Data and Methodology-A reviewShilpa Soi
 
Pengurusan asset dan fasiliti (a+f)
Pengurusan asset dan fasiliti (a+f)Pengurusan asset dan fasiliti (a+f)
Pengurusan asset dan fasiliti (a+f)deriliumboy
 
Asset & Facility Management Consulting Services
Asset & Facility Management Consulting ServicesAsset & Facility Management Consulting Services
Asset & Facility Management Consulting ServicesRosmiman Asset Management
 
Big Data: It’s all about the Use Cases
Big Data: It’s all about the Use CasesBig Data: It’s all about the Use Cases
Big Data: It’s all about the Use CasesJames Serra
 
Innovation in Facilities Management
Innovation in Facilities ManagementInnovation in Facilities Management
Innovation in Facilities Managementchrisdpayne
 
Predictive Analytics: Extending asset management framework for multi-industry...
Predictive Analytics: Extending asset management framework for multi-industry...Predictive Analytics: Extending asset management framework for multi-industry...
Predictive Analytics: Extending asset management framework for multi-industry...Capgemini
 
Big Data Analytics in Energy & Utilities
Big Data Analytics in Energy & UtilitiesBig Data Analytics in Energy & Utilities
Big Data Analytics in Energy & UtilitiesAnders Quitzau
 
TEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkTEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkVolker Hirsch
 

Viewers also liked (12)

Operational Excellence & Mobile
Operational Excellence & MobileOperational Excellence & Mobile
Operational Excellence & Mobile
 
Big Data, Analytics & its impact on asset management
Big Data, Analytics & its impact on asset managementBig Data, Analytics & its impact on asset management
Big Data, Analytics & its impact on asset management
 
BIG Data and Methodology-A review
BIG Data and Methodology-A reviewBIG Data and Methodology-A review
BIG Data and Methodology-A review
 
Asset management-cda
Asset management-cdaAsset management-cda
Asset management-cda
 
Connecting assets and facilities with IoT
Connecting assets and facilities with IoTConnecting assets and facilities with IoT
Connecting assets and facilities with IoT
 
Pengurusan asset dan fasiliti (a+f)
Pengurusan asset dan fasiliti (a+f)Pengurusan asset dan fasiliti (a+f)
Pengurusan asset dan fasiliti (a+f)
 
Asset & Facility Management Consulting Services
Asset & Facility Management Consulting ServicesAsset & Facility Management Consulting Services
Asset & Facility Management Consulting Services
 
Big Data: It’s all about the Use Cases
Big Data: It’s all about the Use CasesBig Data: It’s all about the Use Cases
Big Data: It’s all about the Use Cases
 
Innovation in Facilities Management
Innovation in Facilities ManagementInnovation in Facilities Management
Innovation in Facilities Management
 
Predictive Analytics: Extending asset management framework for multi-industry...
Predictive Analytics: Extending asset management framework for multi-industry...Predictive Analytics: Extending asset management framework for multi-industry...
Predictive Analytics: Extending asset management framework for multi-industry...
 
Big Data Analytics in Energy & Utilities
Big Data Analytics in Energy & UtilitiesBig Data Analytics in Energy & Utilities
Big Data Analytics in Energy & Utilities
 
TEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkTEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of Work
 

Similar to Introduciton to Python

Spark and C Integration
Spark and C IntegrationSpark and C Integration
Spark and C IntegrationMoshe Kaplan
 
Automatic and Interpretable Machine Learning with H2O and LIME
Automatic and Interpretable Machine Learning with H2O and LIMEAutomatic and Interpretable Machine Learning with H2O and LIME
Automatic and Interpretable Machine Learning with H2O and LIMEJo-fai Chow
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfAnassElHousni
 
An Introduction to CMake
An Introduction to CMakeAn Introduction to CMake
An Introduction to CMakeICS
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language CourseVivek chan
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxNEHARAJPUT239591
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJmeharikiros2
 
Static PIE, How and Why - Metasploit's new POSIX payload: Mettle
Static PIE, How and Why - Metasploit's new POSIX payload: MettleStatic PIE, How and Why - Metasploit's new POSIX payload: Mettle
Static PIE, How and Why - Metasploit's new POSIX payload: MettleBrent Cook
 
ODU ACM Python & Memento Presentation
ODU ACM Python & Memento PresentationODU ACM Python & Memento Presentation
ODU ACM Python & Memento PresentationScottAinsworth
 
Verification of Concurrent and Distributed Systems
Verification of Concurrent and Distributed SystemsVerification of Concurrent and Distributed Systems
Verification of Concurrent and Distributed SystemsMykola Novik
 
Concurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System DiscussionConcurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System DiscussionCherryBerry2
 
MongoDB Best Practices for Developers
MongoDB Best Practices for DevelopersMongoDB Best Practices for Developers
MongoDB Best Practices for DevelopersMoshe Kaplan
 
20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo Omura
20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo Omura20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo Omura
20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo OmuraPreferred Networks
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docMayurWagh46
 
Processes And Job Control
Processes And Job ControlProcesses And Job Control
Processes And Job Controlahmad bassiouny
 
KubeCon EU 2016: Getting the Jobs Done With Kubernetes
KubeCon EU 2016: Getting the Jobs Done With KubernetesKubeCon EU 2016: Getting the Jobs Done With Kubernetes
KubeCon EU 2016: Getting the Jobs Done With KubernetesKubeAcademy
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...bhargavi804095
 
Where's the source, Luke? : How to find and debug the code behind Plone
Where's the source, Luke? : How to find and debug the code behind PloneWhere's the source, Luke? : How to find and debug the code behind Plone
Where's the source, Luke? : How to find and debug the code behind PloneVincenzo Barone
 
"Deployment for free": removing the need to write model deployment code at St...
"Deployment for free": removing the need to write model deployment code at St..."Deployment for free": removing the need to write model deployment code at St...
"Deployment for free": removing the need to write model deployment code at St...Stefan Krawczyk
 

Similar to Introduciton to Python (20)

Spark and C Integration
Spark and C IntegrationSpark and C Integration
Spark and C Integration
 
Automatic and Interpretable Machine Learning with H2O and LIME
Automatic and Interpretable Machine Learning with H2O and LIMEAutomatic and Interpretable Machine Learning with H2O and LIME
Automatic and Interpretable Machine Learning with H2O and LIME
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdf
 
An Introduction to CMake
An Introduction to CMakeAn Introduction to CMake
An Introduction to CMake
 
CS4961-L9.ppt
CS4961-L9.pptCS4961-L9.ppt
CS4961-L9.ppt
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language Course
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptx
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
 
Static PIE, How and Why - Metasploit's new POSIX payload: Mettle
Static PIE, How and Why - Metasploit's new POSIX payload: MettleStatic PIE, How and Why - Metasploit's new POSIX payload: Mettle
Static PIE, How and Why - Metasploit's new POSIX payload: Mettle
 
ODU ACM Python & Memento Presentation
ODU ACM Python & Memento PresentationODU ACM Python & Memento Presentation
ODU ACM Python & Memento Presentation
 
Verification of Concurrent and Distributed Systems
Verification of Concurrent and Distributed SystemsVerification of Concurrent and Distributed Systems
Verification of Concurrent and Distributed Systems
 
Concurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System DiscussionConcurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System Discussion
 
MongoDB Best Practices for Developers
MongoDB Best Practices for DevelopersMongoDB Best Practices for Developers
MongoDB Best Practices for Developers
 
20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo Omura
20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo Omura20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo Omura
20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo Omura
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).doc
 
Processes And Job Control
Processes And Job ControlProcesses And Job Control
Processes And Job Control
 
KubeCon EU 2016: Getting the Jobs Done With Kubernetes
KubeCon EU 2016: Getting the Jobs Done With KubernetesKubeCon EU 2016: Getting the Jobs Done With Kubernetes
KubeCon EU 2016: Getting the Jobs Done With Kubernetes
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...
 
Where's the source, Luke? : How to find and debug the code behind Plone
Where's the source, Luke? : How to find and debug the code behind PloneWhere's the source, Luke? : How to find and debug the code behind Plone
Where's the source, Luke? : How to find and debug the code behind Plone
 
"Deployment for free": removing the need to write model deployment code at St...
"Deployment for free": removing the need to write model deployment code at St..."Deployment for free": removing the need to write model deployment code at St...
"Deployment for free": removing the need to write model deployment code at St...
 

More from Moshe Kaplan

Redis training for java software engineers
Redis training for java software engineersRedis training for java software engineers
Redis training for java software engineersMoshe Kaplan
 
MongoDB training for java software engineers
MongoDB training for java software engineersMongoDB training for java software engineers
MongoDB training for java software engineersMoshe Kaplan
 
MongoDB from Basics to Scale
MongoDB from Basics to ScaleMongoDB from Basics to Scale
MongoDB from Basics to ScaleMoshe Kaplan
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMoshe Kaplan
 
MySQL Multi Master Replication
MySQL Multi Master ReplicationMySQL Multi Master Replication
MySQL Multi Master ReplicationMoshe Kaplan
 
mongoDB Performance
mongoDB PerformancemongoDB Performance
mongoDB PerformanceMoshe Kaplan
 
MySQL crash course by moshe kaplan
MySQL crash course by moshe kaplanMySQL crash course by moshe kaplan
MySQL crash course by moshe kaplanMoshe Kaplan
 
Expert Days: The VP R&D Open Seminar: Project Management
Expert Days: The VP R&D Open Seminar: Project ManagementExpert Days: The VP R&D Open Seminar: Project Management
Expert Days: The VP R&D Open Seminar: Project ManagementMoshe Kaplan
 
Expert Days 2011: The VP R&D Open Seminar: Systems Performance Seminar
Expert Days 2011: The VP R&D Open Seminar: Systems Performance Seminar Expert Days 2011: The VP R&D Open Seminar: Systems Performance Seminar
Expert Days 2011: The VP R&D Open Seminar: Systems Performance Seminar Moshe Kaplan
 
Database2011 MySQL Sharding
Database2011 MySQL ShardingDatabase2011 MySQL Sharding
Database2011 MySQL ShardingMoshe Kaplan
 
Cloud Computing Design Best Practices
Cloud Computing Design Best PracticesCloud Computing Design Best Practices
Cloud Computing Design Best PracticesMoshe Kaplan
 
Better Gantts and Project Management
Better Gantts and Project Management Better Gantts and Project Management
Better Gantts and Project Management Moshe Kaplan
 
Better Gantts and Project Management
Better Gantts and Project ManagementBetter Gantts and Project Management
Better Gantts and Project ManagementMoshe Kaplan
 
Better gantts and project management
Better gantts and project managementBetter gantts and project management
Better gantts and project managementMoshe Kaplan
 
Extract The Traffic From The Db
Extract The Traffic From The DbExtract The Traffic From The Db
Extract The Traffic From The DbMoshe Kaplan
 
Organization Wide Performance Methodology (ITIL)
Organization Wide Performance Methodology (ITIL)Organization Wide Performance Methodology (ITIL)
Organization Wide Performance Methodology (ITIL)Moshe Kaplan
 

More from Moshe Kaplan (18)

Git Tutorial
Git TutorialGit Tutorial
Git Tutorial
 
Redis training for java software engineers
Redis training for java software engineersRedis training for java software engineers
Redis training for java software engineers
 
MongoDB training for java software engineers
MongoDB training for java software engineersMongoDB training for java software engineers
MongoDB training for java software engineers
 
MongoDB from Basics to Scale
MongoDB from Basics to ScaleMongoDB from Basics to Scale
MongoDB from Basics to Scale
 
The api economy
The api economyThe api economy
The api economy
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MySQL Multi Master Replication
MySQL Multi Master ReplicationMySQL Multi Master Replication
MySQL Multi Master Replication
 
mongoDB Performance
mongoDB PerformancemongoDB Performance
mongoDB Performance
 
MySQL crash course by moshe kaplan
MySQL crash course by moshe kaplanMySQL crash course by moshe kaplan
MySQL crash course by moshe kaplan
 
Expert Days: The VP R&D Open Seminar: Project Management
Expert Days: The VP R&D Open Seminar: Project ManagementExpert Days: The VP R&D Open Seminar: Project Management
Expert Days: The VP R&D Open Seminar: Project Management
 
Expert Days 2011: The VP R&D Open Seminar: Systems Performance Seminar
Expert Days 2011: The VP R&D Open Seminar: Systems Performance Seminar Expert Days 2011: The VP R&D Open Seminar: Systems Performance Seminar
Expert Days 2011: The VP R&D Open Seminar: Systems Performance Seminar
 
Database2011 MySQL Sharding
Database2011 MySQL ShardingDatabase2011 MySQL Sharding
Database2011 MySQL Sharding
 
Cloud Computing Design Best Practices
Cloud Computing Design Best PracticesCloud Computing Design Best Practices
Cloud Computing Design Best Practices
 
Better Gantts and Project Management
Better Gantts and Project Management Better Gantts and Project Management
Better Gantts and Project Management
 
Better Gantts and Project Management
Better Gantts and Project ManagementBetter Gantts and Project Management
Better Gantts and Project Management
 
Better gantts and project management
Better gantts and project managementBetter gantts and project management
Better gantts and project management
 
Extract The Traffic From The Db
Extract The Traffic From The DbExtract The Traffic From The Db
Extract The Traffic From The Db
 
Organization Wide Performance Methodology (ITIL)
Organization Wide Performance Methodology (ITIL)Organization Wide Performance Methodology (ITIL)
Organization Wide Performance Methodology (ITIL)
 

Recently uploaded

Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 

Recently uploaded (20)

Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 

Introduciton to Python

  • 1. Creating Big Data: Introduction to Python Moshe Kaplan moshe.kaplan@brightaqua.com
  • 2. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Moshe Kaplan > Scale Hacker: Architecture (Sys and Data) R&D Solving Problems > Blogs: http://top-performance.blogspot.com http://blogs.microsoft.co.il/vprnd 2
  • 3. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com About Me: It’s all About Scale 3
  • 4. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com INTRODUCTION Background 4 http://geekandpoke.typepad.com/geekandpoke/2008/07/one-day-in-the.html
  • 5. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Wny Python? Simple and readable Indentation: hard to mess OOP and functional Dynamic and auto memory management Can be packaged Cross platform Wide number of libraries Works great w/ Java, C, .Net 5
  • 6. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Who is Behind? Python Software Foundation ~1M USD annual budget Created at 1989 Top 10 from 2008 6 https://en.wikipedia.org/wiki/Python_(programming_language)
  • 7. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Who is Using? 7 http://www.dhruvb.com/blog/images/slides/python/using-python.png
  • 8. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Python Version 2.X  Existing Projects 3.X  New Projects Not so backwards compatible 8
  • 9. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Materials 9 https://www.tocode.co.il 10% Discount Coupon Code: PyApplied
  • 10. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com IDEs You can use Notepad++ 10
  • 11. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com HELLO WORLD Background 11
  • 12. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com 12 http://www.dhruvb.com/blog/presentations/python/#/2
  • 13. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com 13 http://www.dhruvb.com/blog/presentations/python/#/2
  • 14. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com VARIABLES, NUMBERS AND STRINGS Python 14
  • 15. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com C:>Python Type "help", "copyright", "credits" or "license" for more information. >>> a = "hello" >>> print(a) hello >>> print(type(a)) <class 'str'> >>> a = 1 >>> print(type(a)) <class 'int'> >>> Variables 15 Auto Declaration Auto type assignment
  • 16. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Numbers Integer (int) Floating Complex (a+ib) 16 http://www.slideshare.net/TahaniAlManie/python-3-programming-language
  • 17. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Strings Immutable (cannot modify) Char is a single char string Starts w/ 0 and support –N 17 >>> a = "hello" >>> a[0] 'h' >>> a[-1] 'o'
  • 18. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Strings Methods 18 http://www.slideshare.net/TahaniAlManie/python-3-programming-language
  • 19. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Strings Operators 19 http://www.slideshare.net/TahaniAlManie/python-3-programming-language
  • 20. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com LISTS AND TUPLES Python 20
  • 21. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Lists Basics Mutable Support multi types Again 0–N 21 >>> l = [1, 'b', 'ccc'] >>> print(l[0]) 1 >>> print(l[1:2]); ['b'] >>> l[2] = 3 >>> print(l) >>> del(l[0]) >>> print(l) ['b', 3]
  • 22. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Lists Magic Supports list in a list For each: 22 >>> a = [1, 2, 3] >>> [x ** 2 for x in a] [1, 4, 9] http://www.slideshare.net/TahaniAlManie/python-3-programming-language
  • 23. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Tuples Similar functionality to lists Immutable (cannot modify) Faster than lists Perfect for functional programming 23 >>> t = (1, 'b', 'ccc') >>> t[0] = 2 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'tuple' object does not support item assignment
  • 24. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Dictionaries Basics Key/Value pairs (JSON like) Mutable (cannot modify) 24 >>> d = {'name':'moshe', 'course':'PySpark'} >>> print(d['name']) moshe >>> print(d.keys()) dict_keys(['name', 'course']) >>> print(d.values()) dict_values(['moshe', 'PySpark']) >>> print(d.items()) dict_items([('name', 'moshe'), ('course', 'PySpark')])
  • 25. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Dictionaries Methods 25 http://www.slideshare.net/TahaniAlManie/python-3-programming-language
  • 26. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com FUNCTIONS Python 26
  • 27. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Functions Basics Flexible parameters: 27 >>> def a(name = "moshe", course = "pycourse"): ... print(name + ": " + course) ... >>> a() moshe: pycourse >>> a("roni") roni: pycourse >>> a(course = "spark") moshe: spark
  • 28. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Variable Length Parameters and Refs Not ByVal and not ByRef: Mutuable: Object Reference (array) Immutable: Change pointer each time (string) 28 >>> def f(*tup): ... for t in tup: ... print(t) ... >>> >>> >>> f(1, "b", "ccc") 1 b ccc is vs ==
  • 29. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com IF STATEMENTS AND LOOPS Python 29
  • 30. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com if True or False conditions (no null) Non Null  True Non Zero  True 30 >>> b = True >>> if b: ... print(1) ... elif b != True: ... print(2) ... else: ... print(3) 1 >>> x = 'correct' if b == True else 'wrong'
  • 31. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com For Loops: Strings 31 >>> for letter in 'python': ... print(letter) p y t h o n
  • 32. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com For Loops: For Each 32 >>> for x in range(1, 5): ... print(x) ... 1 2 3 4
  • 33. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com While continue: Well, continue break: Well, break pass: Void, due to indentation 33 >>> while (x < 5): ... print(x) ... x = x + 1 0 1 2 3 4
  • 34. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com INPUT AND BASIC TERMINAL APPS Python 34
  • 35. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Files f = open(“file_name” [, access_mode] [,buffering]) “r”  read “w”  recreate “a”  append “b”  add for binary reading i = f.read()  All at once line = f.readline()  Single line lines = f.readlines()  All at once to a list f.write(string) f.close() 35
  • 36. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com I/O Immutable (cannot modify) Char is a single char string Starts w/ 0 and support –N 36 shuffelBlocks = (raw_input("Shuffel Blocks (y/n): ") == 'y') print(shuffelBlocks) assert(type(a) == type(1))
  • 37. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com CLASSES AND ENTERPRISE LEVEL PROGRAMMING Python 37
  • 38. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Classes 38 > Python class.py Moshe is earning too much Roni is earning 100 Total Employees: 2 Static variable Constructor Object var
  • 39. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Inheritance By default  Everything public __attribute  Turn to private Reflection++: Multiple inheritance is supported 39 class shape: ... class Circle(shape): ...
  • 40. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Modules and Imports Use 3rd party code: Functions Classes Attributes 40 >>> import module1 [, module2] >>> from module3 import name1 [, name2] Only specific attributes
  • 41. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Creating Modules Simple header And we are done… 41 """file my_module.py Module 'my_module': my special module """ def my_func(a): if __name__ == '__main__': print my_func(1)
  • 42. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Packaging 42 def is_number(s): try: int(s) return True except ValueError: return False if __name__ == '__main__': COLOR_BREAK = 'blue' COLOR_HEADER_FOOTER = 'darkCyan';
  • 43. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Python Compiler See also .pyc file in your stack 43
  • 44. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Python Integration 44
  • 45. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com EXCEPTIONS Python 45
  • 46. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Try and Except Common: NameError TypeError IndexError KeyError 46 try: print(getattr(moshe, "course")) except NameError: print("no attribute1")
  • 47. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com TESTING Python 47
  • 48. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com How to Do that? 48 import my_module import unittest class my_module_test(unittest.TestCase): def test_method1(self): self.assertFalse(method1(1)) if __name__ == '__main__': unittest.main()
  • 49. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com PREPARE FOR SPARK Python 49
  • 50. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Functions are Objects 50 # Evil Code… >> log, exp = exp, log >> r = [ -1, 0, 1] >> map(abs, r) [1, 0, 1] >> def sum(x, y): return x+y >> reduce(sum, r) 0 >> def large(x): return x > 0 >> filter(large, r) [1]
  • 51. © All rights reserved: Moshe Kaplan http://top-performance.blogspot.com Thank You ! Moshe Kaplan moshe.kaplan@brightaqua.com 054-2291978