introduction to python on ibm i - the omni user home … to python on ibm i © 2017 rogue wave...
TRANSCRIPT
![Page 1: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/1.jpg)
1© 2017 Rogue Wave Software, Inc. All Rights Reserved. 1
Introduction to Python on IBM i
![Page 2: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/2.jpg)
2© 2017 Rogue Wave Software, Inc. All Rights Reserved. 2
Agenda
• A little about Python
• Why use Python?
• How to install/determine if installed
• Syntax101
– Variables
– Strings
– Functions
– Command Line
• DB2 Data Access
![Page 3: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/3.jpg)
3© 2017 Rogue Wave Software, Inc. All Rights Reserved. 3
Acknowledgements
• Kevin Adler
• Tony Cairns
• Jesse Gorzinski
• Memegenerator
• Corn chips & salsa
• Clean socks
• and, of course,
– spam
![Page 4: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/4.jpg)
4© 2017 Rogue Wave Software, Inc. All Rights Reserved. 4
Before you freak out
• Why isn’t Mike talking about PHP?
– Zend WAS the PHP company
– Rogue Wave IS the Open Source company
• Support for 300+ Open Source projects
• And, of course, PHP
![Page 5: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/5.jpg)
5© 2017 Rogue Wave Software, Inc. All Rights Reserved. 5
A little about Python
![Page 6: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/6.jpg)
6© 2017 Rogue Wave Software, Inc. All Rights Reserved. 6
What is it really?
General purpose programming language
Easy to get started
Simple syntax
Great for integrations
Access to C and other API
Infrastructure first, but applications too.
Thanks: Tahani Alamanie
![Page 7: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/7.jpg)
7© 2017 Rogue Wave Software, Inc. All Rights Reserved. 7
Historically…
Python was conceptualized by Guido Van Rossum in the late 1980s.
Rossum published the first version of Python code (0.9.0) in February 1991 at the
CWI (Centrum Wiskunde & Informatica) in the Netherlands , Amsterdam.
Python is derived from ABC programming language, which is a general-purpose
programming language that had been developed at the CWI.
Rossum chose the name "Python", since he was a big fan of Monty Python's
Flying Circus.
Python is now maintained by a core development team at the institute, although
Rossum still holds a vital role in directing its progress.
Thanks: Tahani Alamanie
![Page 8: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/8.jpg)
8© 2017 Rogue Wave Software, Inc. All Rights Reserved. 8
Python lineage
• Python 1 – 1994
• Python 2 – 2000 (Not dead yet…)
– 2.7 - 2010
• Python 3 – 2008
– 3.5 – 2015
– 3.6.1 – March 2017
![Page 9: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/9.jpg)
9© 2017 Rogue Wave Software, Inc. All Rights Reserved. 9
Python 2 or 3?
![Page 10: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/10.jpg)
10© 2017 Rogue Wave Software, Inc. All Rights Reserved. 10
What’s the diff?
• Example:
• Python 2 print statement replaced by function:
– Python2 – print "Hello World!"
– Python3 - print("Hello World!")
• Many more differences, tho…
![Page 11: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/11.jpg)
11© 2017 Rogue Wave Software, Inc. All Rights Reserved. 11
Why use it?
![Page 12: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/12.jpg)
12© 2017 Rogue Wave Software, Inc. All Rights Reserved. 12
Python==hot
• RPG is 45, COBOL is 25, ugh…
![Page 13: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/13.jpg)
13© 2017 Rogue Wave Software, Inc. All Rights Reserved. 13
Some reasons folks use Python
• Open source is free, right?
– Yes, no…well – sort of…
– No charge LP on IBM i – 5733OPS
• Only scripting language to support multiple inheritance
• Multi-threading
– Stateful, not Async like Node
– But same motivation as Node, non-blocking
• Applications develop faster
– Extensive standard library that is constantly evolving
– Frameworks such as Bottle
![Page 14: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/14.jpg)
14© 2017 Rogue Wave Software, Inc. All Rights Reserved. 14
Industries using Python
• Technology
– Geospatial, Machine Learning
– Honeywell - Build automation
• Manufacturing
– D-Link updates – Multithreaded
– Phillips – Robot programming and sequencing
• Entertainment
– ILM – Scripting CGI Intensive films
– Video gaming
• Transportation
– Airports – Frequentis for weather info
• US, Denmark, Iceland, Hong Kong, etc.
![Page 15: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/15.jpg)
15© 2017 Rogue Wave Software, Inc. All Rights Reserved. 15
Companies using Python
• YouTube - Backend
• Facebook – (see next slide)
• Dropbox
• NASA – Weather and more
• IBM
• Mozilla
• Red
• Quora
– Why python?
![Page 16: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/16.jpg)
16© 2017 Rogue Wave Software, Inc. All Rights Reserved. 16
Facebook in detail
• Top three languages
– Hack (fork of PHP)
– C++
– Python
• Infrastructure management
– Network switch setup
– Core services (DNS, etc,)
– Server imaging, burnin-in.
• Platform services: Job Engine, team workflow management
https://code.facebook.com/posts/1040181199381023/python-in-production-engineering/
![Page 17: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/17.jpg)
17© 2017 Rogue Wave Software, Inc. All Rights Reserved. 17
Got Python?
![Page 18: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/18.jpg)
18© 2017 Rogue Wave Software, Inc. All Rights Reserved. 18
Details at Developerworks…
• https://www.ibm.com/developerworks/community/wikis/home?lang=e
n#!/wiki/IBM%20i%20Technology%20Updates/page/Open%20Source%
20Technologies
![Page 19: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/19.jpg)
19© 2017 Rogue Wave Software, Inc. All Rights Reserved. 19
Which one?
• Python 3 is LPP option 2
• Python 2 is LPP option 4
• Correct answer: It depends…
– Many existing libraries are Python 2
– But 90%+ are also Python 3 compliant, or on their way
• Python 2.7 will retire in less than 3 years (EOL==2020)
![Page 20: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/20.jpg)
20© 2017 Rogue Wave Software, Inc. All Rights Reserved. 20
Need Licensed Programs
• 5733OPS Base and option 2 or 4
![Page 21: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/21.jpg)
21© 2017 Rogue Wave Software, Inc. All Rights Reserved. 21
Python in action
• Command line via green screen (CALL QP2TERM)
![Page 22: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/22.jpg)
22© 2017 Rogue Wave Software, Inc. All Rights Reserved. 22
Hello world?
![Page 23: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/23.jpg)
23© 2017 Rogue Wave Software, Inc. All Rights Reserved. 23
Most prefer SSH
• Command line via SSH terminal
![Page 24: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/24.jpg)
24© 2017 Rogue Wave Software, Inc. All Rights Reserved. 24
Hello World, again?
![Page 25: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/25.jpg)
25© 2017 Rogue Wave Software, Inc. All Rights Reserved. 25
IDE?
![Page 26: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/26.jpg)
26© 2017 Rogue Wave Software, Inc. All Rights Reserved. 26
Zend Studio
• No, you don’t need to buy Zend Studio
• Use Orion, etc.
• But if you have Studio or RDi…
– Consider something from Eclipse.org
– I grabbed PyDev
![Page 27: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/27.jpg)
27© 2017 Rogue Wave Software, Inc. All Rights Reserved. 27
Eclipse
![Page 28: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/28.jpg)
28© 2017 Rogue Wave Software, Inc. All Rights Reserved. 28
Alternatives to IBM i when learning
• What’s that? The boss won’t let you install Python?
– Consider repl.it
![Page 29: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/29.jpg)
29© 2017 Rogue Wave Software, Inc. All Rights Reserved. 29
Alternatives to IBM i when learning
• How about your PC?
• Goto the Python site:
– Download
– Install
– Viola!
![Page 30: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/30.jpg)
30© 2017 Rogue Wave Software, Inc. All Rights Reserved. 30
Download PyDev from Eclipse
![Page 31: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/31.jpg)
31© 2017 Rogue Wave Software, Inc. All Rights Reserved. 31
Capture URL
• Follow prompts
![Page 32: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/32.jpg)
32© 2017 Rogue Wave Software, Inc. All Rights Reserved. 32
Editor for Eclipse
• Select what you like
• Next
![Page 33: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/33.jpg)
33© 2017 Rogue Wave Software, Inc. All Rights Reserved. 33
Confirm versions
• Next
![Page 34: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/34.jpg)
34© 2017 Rogue Wave Software, Inc. All Rights Reserved. 34
Accept terms and EULA
• Finish
![Page 35: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/35.jpg)
35© 2017 Rogue Wave Software, Inc. All Rights Reserved. 35
Watch the pretty status bar
![Page 36: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/36.jpg)
36© 2017 Rogue Wave Software, Inc. All Rights Reserved. 36
Python in Eclipse (i.e. Zend Studio)
• I bet RDi works, too!
![Page 37: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/37.jpg)
37© 2017 Rogue Wave Software, Inc. All Rights Reserved. 37
Hello world….again…
• Create a file like Ex01hello.py
• Open the file
• Key up some code and click save
![Page 38: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/38.jpg)
38© 2017 Rogue Wave Software, Inc. All Rights Reserved. 38
Hello world….again…
• Change the file
• Click save
• Back to qp2term & F9
![Page 39: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/39.jpg)
39© 2017 Rogue Wave Software, Inc. All Rights Reserved. 39
Syntax
![Page 40: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/40.jpg)
40© 2017 Rogue Wave Software, Inc. All Rights Reserved. 40
How is it written
• Indentation means EVERYTHING
– Don’t use tab
– 4 spaces is the best practice
– Mismatched indents can cause failures. Good luck finding…
– Mismatched spaces and tabs will cause failures
• No need for scope terminators like other languages
• Colon introduces start block, then indent
• Much more readable than other languages
• Get a good editor!!!
![Page 41: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/41.jpg)
41© 2017 Rogue Wave Software, Inc. All Rights Reserved. 41
Indentation
![Page 42: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/42.jpg)
42© 2017 Rogue Wave Software, Inc. All Rights Reserved. 42
Operators – Similar to Java, PHP, C, etc.
• Comparison
– Assignment =
– Comparison ==
– Inequality !=
– Less than <
– Greater than >
– Less than or equal to <=
– Greater than or equal to >=
• Mathematical
– Addition +
– Multiplication *
– Division /
– Floor division //
– Modulus %
– Exponentiation **
• Booleans
– And
– Or
– Not
![Page 43: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/43.jpg)
43© 2017 Rogue Wave Software, Inc. All Rights Reserved. 43
Variables
![Page 44: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/44.jpg)
44© 2017 Rogue Wave Software, Inc. All Rights Reserved. 44
Data Types – yeah…about that
• Int
– Integer of unlimited size
• Float
– System defined precision
• Complex
– Complex with real and imaginary parts
• Bool
– TRUE & FALSE
![Page 45: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/45.jpg)
45© 2017 Rogue Wave Software, Inc. All Rights Reserved. 45
Built in types
• Str
– Character string composed of Unicode
• Bytes and bytearray
– Sequences of bytes
• List and tuple (list/array/data structure)
• Range
– Start, end, step
• Set & frozenset
– Unordered set of terms
• Dict
– Associative array (dictionary, hash map)
![Page 46: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/46.jpg)
46© 2017 Rogue Wave Software, Inc. All Rights Reserved. 46
Variables on the fly
• Case sensitive
• camelCase
• Who are you? type()
![Page 47: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/47.jpg)
47© 2017 Rogue Wave Software, Inc. All Rights Reserved. 47
Variables in a file
![Page 48: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/48.jpg)
48© 2017 Rogue Wave Software, Inc. All Rights Reserved. 48
Data Type?
![Page 49: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/49.jpg)
49© 2017 Rogue Wave Software, Inc. All Rights Reserved. 49
Every variable is implemented as a class!
![Page 50: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/50.jpg)
50© 2017 Rogue Wave Software, Inc. All Rights Reserved. 50
And now for something completely different
![Page 51: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/51.jpg)
51© 2017 Rogue Wave Software, Inc. All Rights Reserved. 51
It’s OK….
• Monty Python references are not only acceptable…
– They are encouraged!
• Documentation is littered with references
• Examples are well covered
![Page 52: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/52.jpg)
52© 2017 Rogue Wave Software, Inc. All Rights Reserved. 52
Back to Variables
• Numbrs - 3 Data Types
– Int 1,2,42
– Float 3.14159
– Complex: <real> + <imaginary> (not used much…)
![Page 53: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/53.jpg)
53© 2017 Rogue Wave Software, Inc. All Rights Reserved. 53
Strings
• Immutable objects, cannot change value
• Can reassign. (dynamic typing)
• Single or Double quotes, OK (even triple…)
• Index starts at 0
![Page 54: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/54.jpg)
54© 2017 Rogue Wave Software, Inc. All Rights Reserved. 54
String formatting
• Interpolation, of sorts
![Page 55: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/55.jpg)
55© 2017 Rogue Wave Software, Inc. All Rights Reserved. 55
Lists
• Ordered group, similar to array
• Different data types, ok
• Multi-dimensional (sub lists)
• Mutable (changeable)
![Page 56: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/56.jpg)
56© 2017 Rogue Wave Software, Inc. All Rights Reserved. 56
Tuples
• Similar to lists
• Immutable (don’t change once created)
• Use parenthesis instead of brackets
![Page 57: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/57.jpg)
57© 2017 Rogue Wave Software, Inc. All Rights Reserved. 57
Dictionary
• Again, like lists but more like hash table
• Mutable
• Key value pairs
![Page 58: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/58.jpg)
58© 2017 Rogue Wave Software, Inc. All Rights Reserved. 58
Control Structures
![Page 59: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/59.jpg)
59© 2017 Rogue Wave Software, Inc. All Rights Reserved. 59
Ifs
![Page 60: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/60.jpg)
60© 2017 Rogue Wave Software, Inc. All Rights Reserved. 60
For loop
![Page 61: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/61.jpg)
61© 2017 Rogue Wave Software, Inc. All Rights Reserved. 61
While loop
![Page 62: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/62.jpg)
62© 2017 Rogue Wave Software, Inc. All Rights Reserved. 62
Functions
![Page 63: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/63.jpg)
63© 2017 Rogue Wave Software, Inc. All Rights Reserved. 63
Basic functions
![Page 64: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/64.jpg)
64© 2017 Rogue Wave Software, Inc. All Rights Reserved. 64
Functions with defaults
![Page 65: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/65.jpg)
65© 2017 Rogue Wave Software, Inc. All Rights Reserved. 65
Functions with keyword arguments
![Page 66: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/66.jpg)
66© 2017 Rogue Wave Software, Inc. All Rights Reserved. 66
Command Line
![Page 67: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/67.jpg)
67© 2017 Rogue Wave Software, Inc. All Rights Reserved. 67
Input from command line• Talk with the script
![Page 68: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/68.jpg)
68© 2017 Rogue Wave Software, Inc. All Rights Reserved. 68
Database
![Page 69: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/69.jpg)
70© 2017 Rogue Wave Software, Inc. All Rights Reserved. 70
Locate the package or “wheel”
![Page 70: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/70.jpg)
71© 2017 Rogue Wave Software, Inc. All Rights Reserved. 71
Install commands
![Page 71: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/71.jpg)
72© 2017 Rogue Wave Software, Inc. All Rights Reserved. 72
Find the connector
• YMMV
• With wheels
![Page 72: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/72.jpg)
73© 2017 Rogue Wave Software, Inc. All Rights Reserved. 73
Run the pip install…
• From the command line
![Page 73: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/73.jpg)
74© 2017 Rogue Wave Software, Inc. All Rights Reserved. 74
What version of the DB2 Extension?
![Page 74: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/74.jpg)
75© 2017 Rogue Wave Software, Inc. All Rights Reserved. 75
Simple database access
• Import the class
• Connect (with or without options
• Open the cursor
• Set the SQL
• Read
![Page 75: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/75.jpg)
76© 2017 Rogue Wave Software, Inc. All Rights Reserved. 76
Simple database access
![Page 76: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/76.jpg)
77© 2017 Rogue Wave Software, Inc. All Rights Reserved. 77
Table information
![Page 77: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/77.jpg)
78© 2017 Rogue Wave Software, Inc. All Rights Reserved. 78
Summary – Why Python?
• Lot’s of libraries
• Make it easy to do stuff
• OPC / OPO
• Education
![Page 78: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/78.jpg)
79© 2017 Rogue Wave Software, Inc. All Rights Reserved. 79
End the session
![Page 79: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/79.jpg)
80© 2017 Rogue Wave Software, Inc. All Rights Reserved. 80
ATTENDConnect with experts.Become an authority.Register now:zendcon.com/register-now
EXPLOREShare, inspire, educate.Network
SPONSORSpotlight your best in enterprise PHP, opensource & frameworks:[email protected]
Visit zendcon.com
![Page 80: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/80.jpg)
81© 2017 Rogue Wave Software, Inc. All Rights Reserved. 81
Who was that masked man?
Mike Pavlak – Solution Consultant, Rogue Wave Software
![Page 81: Introduction to Python on IBM i - The OMNI User Home … to Python on IBM i © 2017 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda •A little about Python •Why use Python?](https://reader031.vdocuments.us/reader031/viewer/2022022510/5ad853627f8b9ab8378d3803/html5/thumbnails/81.jpg)
82© 2017 Rogue Wave Software, Inc. All Rights Reserved. 82