09/26/16 For a Better Future 1
Python Introduction
An Examination of Python for
CHX?
09/26/16 For a Better Future 2
Introduction
 To have a better understanding of
Python role at CHX.
 By Kai Liu, Systems Analyst at
Chicago Stock Exchange.
09/26/16 For a Better Future 3
Topics of Discussion
 What is Python?
 Why Python?
 Perl vs. Python?
 What we need for Python?
 What is CHX structure for Python?
 Work Example.
 Summary
09/26/16 For a Better Future 4
What is Python?
 Python is an interpreted, object-
oriented, high-level programming
language with dynamic semantics. Its
high-level built in data structures,
combined with dynamic typing and
dynamic binding, make it very
attractive for Rapid Application
Development, as well as for use as a
scripting or glue language to connect
existing components together.
Why Python?
 Python's simple, easy to learn syntax
emphasizes readability and therefore reduces the
cost of program maintenance. Python supports
modules and packages, which encourages
program modularity and code reuse. The Python
interpreter and the extensive standard library are
available in source or binary form without charge
for all major platforms, and can be freely
distributed
09/26/16 For a Better Future 5
09/26/16 For a Better Future 6
Perl vs. Python?
 Python and Perl come from a similar background
(Unix scripting, which both have long outgrown),
and support many similar features, but have a
different philosophy. Perl emphasizes support for
common application-oriented tasks, e.g. by having
built-in regular expressions, file scanning and report
generating features. Python emphasizes support for
common programming methodologies such as data
structure design and object-oriented programming,
and encourages programmers to write readable
(and thus maintainable) code by providing an
elegant but not overly cryptic notation.
What we need for Python?
 Python 2.7.8 vs. 3.5+
http://www.activestate.com/activepython/downloa
ds
 PyCharm IDE 2016.1+
 https://www.jetbrains.com/pycharm/download/
 Support for most platforms
 cx_Oracle is a Python extension module that
enables querying and updating of Oracle
databases using a database API 2.0 that is
common to all database access modules. A
number of extensions to the common database
API have also been included in order to take
advantage of some of the features available
exclusively to Oracle. Download at:
https://pypi.python.org/pypi/cx_Oracle/
09/26/16 For a Better Future 7
09/26/16 For a Better Future 8
What is CHX structure for
Python?
• Build components to support template for future scripts:
• Import Modules and Class
Load loadControlParameters() – Get parameters
Load Oracle() Class – Get Oracle Connection
Load GTT_init()– Populate GTT tables
Load Jobs() – Start and End Jobs
Load Get_token_list() – Build Token List
Load Call_System – System Host calls
Load SendEmails() – Send Email out.
Load Exec_Proc() – Run PL/SQL procedure
Load Exec_Refcursor() – Return Refcursor Results
Why do we want to use modules
and Class to build program?
 We want to modularize in our code for reuse and
many other benefits.
 Modules to provide plumbing for basic operation
needed in most of our batch programs.
 Easier to formulate a template for building our
wrapper scripts for our scheduler.
 It also can be use to help rapid prototyping for
development of new program to do task for
specific operation.
 Provide an environment to promote new modules
and a community to be share in other programs.
09/26/16 For a Better Future 9
09/26/16 For a Better Future 10
Work Example
 I had a project that had business requirements to
extracted Attachments from database with Perl.
 The process needed to extract on database
attachments based on a file list provided be user
on which cases were needed for attachments to
be extracted. Originally it was written in Perl. I’ve
rewrote using the Python to provide same
functionality using a new Python Template that
I’ve been developing.
 The codes snipped below is to simplified to help
illustrate the contents of the discussion of using
the Python.
Work Example Cont.
 Real Example:
 The code snipped below for the framework of the body:
loadControlParameters(params) -- Get Parameters
if __name__ == "__main__":
main(sys.argv[1:]) -- Get arguments
db = Oracle() -- Established Oracle connection
…
p_SQL = """WITH
aPerson AS … “ -- Contains Sql Query
09/26/16 For a Better Future 11
Work Example Cont.
# Fetch the attachment with proc passed and case list passed.
prc_tab = db.exec_proc(prc_str,list) -- Execute PL/SQL block
case = db.query(p_SQL) -- Execute the Sql Query
# Get and create notes based on Case List.
for Notes in case: -- Loop to get all notes.
-- write files.
09/26/16 For a Better Future 12
Work Example Cont.
 The end result was files extracted out of
the Oracle database. With modules
currently built an developing new
modules for other functions we can quick
have a library of reusable modules to
allow more productivity in programming
for a rapid development for programs to
be at production level quality based on
proven modules that have mature.
09/26/16 For a Better Future 13
09/26/16 For a Better Future 14
Summary?
 The summary is that Python should be consider for future
programs. It’s not here to replace the Perl scripts, but be
consider a future programming language to be productive with
an be maintainable and scalability. There a lots of information
on Python and what it can do. Also, I believe it’s an easy
language to adapt and use for developers coming for Java, Ruby
and C++.
 Python that everyone will notice: the fact that whitespace
(indentation) is actually significant in the language syntax. The
language has no analog of the C and Perl brace syntax; instead,
changes in indentation delimit statement groups.
09/26/16 For a Better Future 15
Thank You
 Q&A?

CHX PYTHON INTRO

  • 1.
    09/26/16 For aBetter Future 1 Python Introduction An Examination of Python for CHX?
  • 2.
    09/26/16 For aBetter Future 2 Introduction  To have a better understanding of Python role at CHX.  By Kai Liu, Systems Analyst at Chicago Stock Exchange.
  • 3.
    09/26/16 For aBetter Future 3 Topics of Discussion  What is Python?  Why Python?  Perl vs. Python?  What we need for Python?  What is CHX structure for Python?  Work Example.  Summary
  • 4.
    09/26/16 For aBetter Future 4 What is Python?  Python is an interpreted, object- oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together.
  • 5.
    Why Python?  Python'ssimple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed 09/26/16 For a Better Future 5
  • 6.
    09/26/16 For aBetter Future 6 Perl vs. Python?  Python and Perl come from a similar background (Unix scripting, which both have long outgrown), and support many similar features, but have a different philosophy. Perl emphasizes support for common application-oriented tasks, e.g. by having built-in regular expressions, file scanning and report generating features. Python emphasizes support for common programming methodologies such as data structure design and object-oriented programming, and encourages programmers to write readable (and thus maintainable) code by providing an elegant but not overly cryptic notation.
  • 7.
    What we needfor Python?  Python 2.7.8 vs. 3.5+ http://www.activestate.com/activepython/downloa ds  PyCharm IDE 2016.1+  https://www.jetbrains.com/pycharm/download/  Support for most platforms  cx_Oracle is a Python extension module that enables querying and updating of Oracle databases using a database API 2.0 that is common to all database access modules. A number of extensions to the common database API have also been included in order to take advantage of some of the features available exclusively to Oracle. Download at: https://pypi.python.org/pypi/cx_Oracle/ 09/26/16 For a Better Future 7
  • 8.
    09/26/16 For aBetter Future 8 What is CHX structure for Python? • Build components to support template for future scripts: • Import Modules and Class Load loadControlParameters() – Get parameters Load Oracle() Class – Get Oracle Connection Load GTT_init()– Populate GTT tables Load Jobs() – Start and End Jobs Load Get_token_list() – Build Token List Load Call_System – System Host calls Load SendEmails() – Send Email out. Load Exec_Proc() – Run PL/SQL procedure Load Exec_Refcursor() – Return Refcursor Results
  • 9.
    Why do wewant to use modules and Class to build program?  We want to modularize in our code for reuse and many other benefits.  Modules to provide plumbing for basic operation needed in most of our batch programs.  Easier to formulate a template for building our wrapper scripts for our scheduler.  It also can be use to help rapid prototyping for development of new program to do task for specific operation.  Provide an environment to promote new modules and a community to be share in other programs. 09/26/16 For a Better Future 9
  • 10.
    09/26/16 For aBetter Future 10 Work Example  I had a project that had business requirements to extracted Attachments from database with Perl.  The process needed to extract on database attachments based on a file list provided be user on which cases were needed for attachments to be extracted. Originally it was written in Perl. I’ve rewrote using the Python to provide same functionality using a new Python Template that I’ve been developing.  The codes snipped below is to simplified to help illustrate the contents of the discussion of using the Python.
  • 11.
    Work Example Cont. Real Example:  The code snipped below for the framework of the body: loadControlParameters(params) -- Get Parameters if __name__ == "__main__": main(sys.argv[1:]) -- Get arguments db = Oracle() -- Established Oracle connection … p_SQL = """WITH aPerson AS … “ -- Contains Sql Query 09/26/16 For a Better Future 11
  • 12.
    Work Example Cont. #Fetch the attachment with proc passed and case list passed. prc_tab = db.exec_proc(prc_str,list) -- Execute PL/SQL block case = db.query(p_SQL) -- Execute the Sql Query # Get and create notes based on Case List. for Notes in case: -- Loop to get all notes. -- write files. 09/26/16 For a Better Future 12
  • 13.
    Work Example Cont. The end result was files extracted out of the Oracle database. With modules currently built an developing new modules for other functions we can quick have a library of reusable modules to allow more productivity in programming for a rapid development for programs to be at production level quality based on proven modules that have mature. 09/26/16 For a Better Future 13
  • 14.
    09/26/16 For aBetter Future 14 Summary?  The summary is that Python should be consider for future programs. It’s not here to replace the Perl scripts, but be consider a future programming language to be productive with an be maintainable and scalability. There a lots of information on Python and what it can do. Also, I believe it’s an easy language to adapt and use for developers coming for Java, Ruby and C++.  Python that everyone will notice: the fact that whitespace (indentation) is actually significant in the language syntax. The language has no analog of the C and Perl brace syntax; instead, changes in indentation delimit statement groups.
  • 15.
    09/26/16 For aBetter Future 15 Thank You  Q&A?