introduction to python for ibm i · 2018-11-26 · ■python was conceptualized by guido van rossum...
TRANSCRIPT
![Page 1: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/1.jpg)
Introduction to Python for IBM i
Mike Pavlak – IT Strategist
![Page 2: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/2.jpg)
2
Agenda
■ A little about Python
■ Why use Python
■ How to install/determine if installed
▶IDE
■ Syntax 101
▶Variables
▶Strings
▶Functions
■ Database
■ Toolkit
![Page 3: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/3.jpg)
3
Acknowledgements
■ Kevin Adler
■ Tony Cairns
■ Jesse Gorzinski
■ Memegenerator
■ Corn chips and salsa
■ Parrots
■ And, of course, spam
![Page 4: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/4.jpg)
A little about Python
![Page 5: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/5.jpg)
5
What is it, really?
■ General purpose language
■ Easy to get started
■ Simple syntax
■ Great for integrations (glue between systems)
■ Access to C and other APIs
■ Infrastructure first, but applications, too
![Page 6: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/6.jpg)
6
Historically…
■ Python was conceptualized by Guido Van Rossum in the late 1980’s
■ Rossum published the first version of Python code (0.9.0) in February of 1991 at the CWI(Centrum Wiskunde & Informatica) in the Netherlands, Amsterdam
■ Python is derived from the ABC programming language, which is a general purpose language that was also developed at CWI.
■ Rossum chose the name “Python” since he was a 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 and as leading “commitor”.
![Page 7: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/7.jpg)
Why Python?
![Page 8: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/8.jpg)
11
/ Data survey 40,000 developers, worldwide
![Page 9: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/9.jpg)
Got Python?
![Page 10: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/10.jpg)
13
Details at Developerworks
■ https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/IBM%20i%20Technology%20Updates/page/Open%20Source%20Technologies
The sun is setting on
OPS!
![Page 11: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/11.jpg)
14
Need licensed program
■ 5733OPS Base and option 2 or 4
![Page 12: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/12.jpg)
15
Times change…
That was then…
…this is now
![Page 13: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/13.jpg)
16
Leverage RPM’s
■ Use ACS to do the heavy lifting! But fire up SSH first.
![Page 14: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/14.jpg)
17
Insert RPM stuff here…
■ Use ACS to do the heavy lifting!
![Page 15: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/15.jpg)
18
Select system and credentials
![Page 16: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/16.jpg)
19
![Page 17: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/17.jpg)
20
![Page 18: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/18.jpg)
21
Now install Python3
![Page 19: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/19.jpg)
22
Info command
![Page 20: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/20.jpg)
23
Confirm “Is this ok [y/n]”
![Page 21: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/21.jpg)
25
Watch the installation until complete
![Page 22: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/22.jpg)
26
Looking back at ACS in the installed tab…
![Page 23: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/23.jpg)
27
Python in action
■ Command line via green screen
![Page 24: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/24.jpg)
28
Hello World
![Page 25: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/25.jpg)
29
Most prefer SSH
■ Command line via SSH terminal
▶Recommended strongly by Jesse!
![Page 26: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/26.jpg)
30
Shell available in ACS (shortcut to )
■ Encrypted
■ BASH, etc.
■ Linux alignment
![Page 27: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/27.jpg)
31
Hello World, again…
![Page 28: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/28.jpg)
IDE
![Page 29: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/29.jpg)
33
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 30: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/30.jpg)
34
Eclipse
![Page 31: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/31.jpg)
35
Download PyDev from Eclipse
![Page 32: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/32.jpg)
36
Capture URL
■ Help➔
▶Install New Software
▶Follow prompts
![Page 33: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/33.jpg)
37
Editor for Eclipse
■ Select what you like
▶Click next
![Page 34: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/34.jpg)
38
Confirm versions
■ Click next again
▶Then accept EULA
![Page 35: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/35.jpg)
39
Watch the pretty status bar
![Page 36: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/36.jpg)
40
Python in Eclipse (i.e. Zend Studio)
■ I bet RDi works, too!
![Page 37: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/37.jpg)
41
Alternatives to IBM i when learning
■ What’s that? The boss won’t let you install Python on the IBM i?
▶Consider repl.it
![Page 38: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/38.jpg)
42
Desktop education at it’s finest
■ How about your PC?
■ Head to Python.org site:
▶ Download
▶ Install
▶ Viola!
![Page 39: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/39.jpg)
43
Python Script in IFS
■ Create a file like Ex01hello.py
■ Open the file
■ Key up some code and click save
■ Rinse, repeat…
![Page 40: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/40.jpg)
Python Syntax Fundamentals
![Page 41: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/41.jpg)
46
How it is written
■ Indentation means EVERYTHING
▶Don’t use tab
▶4 spaces – No more, no less
▶Mismatched indents can cause failures. Good luck finding…
■ No scope terminators like other languages
■ Colon introduces start block, then indent
■ Much more readable than other languages
■ Get a good editor!!!
![Page 42: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/42.jpg)
47
Indentation
![Page 43: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/43.jpg)
48
Operators – Similar to other C derivatives
■ 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 44: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/44.jpg)
SyntaxVariables
![Page 45: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/45.jpg)
50
Data types – yeah…about that…
■ Int
▶Integer of unlimited size
■ Float
▶System defined precision
■ Complex
▶Complex with real and imaginary parts
■ Strings
▶Sequences of character data
■ Bool
▶TRUE & FALSE
![Page 46: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/46.jpg)
51
Variables on the fly
■ Case sensitive
■ camelCase
■ Who are you? type()
![Page 47: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/47.jpg)
52
Variables in a file
![Page 48: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/48.jpg)
53
Data type?
![Page 49: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/49.jpg)
54
Every variable is implemented as a class
![Page 50: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/50.jpg)
55
And now for something completely different
![Page 51: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/51.jpg)
56
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 for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/52.jpg)
57
Back to variables
■ Numbers – 3 Data types
▶Integer 1,2,42
▶Float 3.14159
▶Complex: <real> + <imaginary> (not used much…)
![Page 53: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/53.jpg)
58
Strings
■ Immutable objects, cannot change value
■ Can reassign. (dynamic typing)
■ Single or Double quotes, OK (even triple…)
■ Index starts at 0 (of course…)
![Page 54: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/54.jpg)
59
String formatting
■ Interpolation, of sorts
![Page 55: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/55.jpg)
Set Processing
![Page 56: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/56.jpg)
61
Lists
■ Ordered group, similar to array
■ Different data types, ok
■ Multi-dimensional (sub lists)
■ Mutable (changeable)
![Page 57: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/57.jpg)
62
Tuples
■ Similar to lists
■ Immutable (don’t change once created)
■ Use parenthesis instead of brackets
![Page 58: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/58.jpg)
63
Dictionary
■ Again, like lists but more like hash or PHP Assoc. Array
■ Mutable
■ Key value pairs
![Page 59: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/59.jpg)
Control Structures
![Page 60: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/60.jpg)
65
ifs
![Page 61: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/61.jpg)
66
for loop
![Page 62: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/62.jpg)
67
while loop
![Page 63: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/63.jpg)
Functions
![Page 64: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/64.jpg)
69
Built in functions
■ About 68
▶Math
▶Type
▶Iterables
▶Composite
▶Classes
▶Variables/Reference Scope
▶Misc…
![Page 65: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/65.jpg)
70
Built in’s are straight forward
#rounding...valueIn = 98.5valueOut = round(valueIn)print("\n", valueIn, " becomes ", valueOut, " when rounded!\n")
#set processingMySet1 = [23, 18, 14, 16, 21]minset = min(MySet1)print("\nIn the set ", MySet1, " the minimum value is ", minset)print(" while the maximum value is ", max(MySet1))
#How about that object ID?print("\n the ID for the set above is ", id(MySet1))print("\n the ID for valueIn above is ", id(valueIn))print("\n the ID for min above is ", id(minset))
![Page 66: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/66.jpg)
71
User Defined Functions
![Page 67: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/67.jpg)
72
Functions with defaults
![Page 68: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/68.jpg)
73
Functions with Keyword arguments
![Page 69: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/69.jpg)
Command Line
![Page 70: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/70.jpg)
75
Input from command line
■ “Talk” to the script…
![Page 71: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/71.jpg)
Database
![Page 72: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/72.jpg)
77
Locate the package or “wheel”
![Page 73: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/73.jpg)
78
Install commands
![Page 74: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/74.jpg)
79
Find the connector
■ YMMV
■ With wheels
![Page 75: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/75.jpg)
80
Run the pip install
■ pip == Python installer program
![Page 76: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/76.jpg)
81
What version of the DB2 Extension?
![Page 77: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/77.jpg)
82
Steps for simple database Access
■ Import the class
■ Connect (with or without options
■ Open the cursor
■ Set the SQL
■ Read
![Page 78: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/78.jpg)
83
Simple database access
![Page 79: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/79.jpg)
84
Table info
![Page 80: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/80.jpg)
IBM i Toolkit
![Page 81: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/81.jpg)
86
A few ways to access toolkit
■ Transition from Python2 to Python3 and RPM
▶Broke a few things
▶Under construction
▶This will work
![Page 82: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/82.jpg)
87
Toolkit Version
■ IBM is maintaining version numbers
#import itoolkit
#Version?print("\nThe iToolKit version is: " + itoolkit.__version__ + "\n")
![Page 83: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/83.jpg)
88
CL Command
import itoolkit as tktimport itoolkit.db2.idb2call as Db2tkt
itool = tkt.iToolKit()print("\nThe iToolKit version is: " + tkt.__version__ + "\n")itransport = Db2tkt.iDB2Call('PYUSER1', 'pyuser1')itool.add(tkt.iCmd5250('dsplibl', 'dsplibl'))itool.call(itransport)
# outputcommandOutput = itool.dict_out('dsplibl')if 'error' in commandOutput:
print (commandOutput['error'])exit()
else:print (commandOutput['dsplibl'])
![Page 84: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/84.jpg)
89
Summary – Why Python
■ Lot’s of libraries
■ Make it easy to do stuff
■ OPC / OPO
■ Education
![Page 85: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/85.jpg)
90
End the session
![Page 86: Introduction to Python for IBM i · 2018-11-26 · ■Python was conceptualized by Guido Van Rossum in the late 1980’s ■Rossum published the first version of Python code (0.9.0)](https://reader036.vdocuments.us/reader036/viewer/2022062506/5fb866f9a943b7036c24a5ab/html5/thumbnails/86.jpg)