chx python intro

15
06/28/22 For a Better Future 1 Python Introduction An Examination of Python for CHX?

Upload: kai-liu

Post on 11-Apr-2017

66 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: CHX PYTHON INTRO

05/03/23 For a Better Future 1

Python IntroductionAn Examination of Python for CHX?

Page 2: CHX PYTHON INTRO

05/03/23 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.

Page 3: CHX PYTHON INTRO

05/03/23 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

Page 4: CHX PYTHON INTRO

05/03/23 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.

Page 5: CHX PYTHON INTRO

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

05/03/23 For a Better Future 5

Page 6: CHX PYTHON INTRO

05/03/23 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.

Page 7: CHX PYTHON INTRO

What we need for Python? Python 2.7.8 vs. 3.5+

http://www.activestate.com/activepython/downloads 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/

05/03/23 For a Better Future 7

Page 8: CHX PYTHON INTRO

05/03/23 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 parametersLoad Oracle() Class – Get Oracle ConnectionLoad GTT_init()– Populate GTT tablesLoad Jobs() – Start and End JobsLoad Get_token_list() – Build Token List Load Call_System – System Host callsLoad SendEmails() – Send Email out.Load Exec_Proc() – Run PL/SQL procedureLoad Exec_Refcursor() – Return Refcursor Results

Page 9: CHX PYTHON INTRO

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.

05/03/23 For a Better Future 9

Page 10: CHX PYTHON INTRO

05/03/23 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.

Page 11: CHX PYTHON INTRO

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

05/03/23 For a Better Future 11

Page 12: CHX PYTHON INTRO

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.

05/03/23 For a Better Future 12

Page 13: CHX PYTHON INTRO

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.

05/03/23 For a Better Future 13

Page 14: CHX PYTHON INTRO

05/03/23 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.

Page 15: CHX PYTHON INTRO

05/03/23 For a Better Future 15

Thank You Q&A?