Still learning the Python programming language here. However, along the way, I have found a need to branch out with some add-on modules for specific tasks. One of these is a module for accessing Oracle Databases. The module is cx_Oracle. Performing a query to an Oracle database become this simple process:
import the cx_Oracle module
make your connection to the Oracle database
connection = cx_Oracle.connect(“username”,”password”,”oracle_instance”)
create an instance of the cursor
cursor = connection.cursor()
Perform a query. This demonstrates a simple select query, how to pass some user input as an argument to it, and how to do something something with the result.
user_input = str.upper(str(input(“Please provide value to query>>”)))
cursor.execute(“select some_field from some_table where some_field like :arg_1”, arg_1 = user_input)
for some_field in cursor:
In the process of learning Python, I have given myself a programming exercise to do. This is a standard thing I do whenever learning a new programming language and I have used this same exercise several times before. It is a simple text based game that simply lets a user explore a maze of rooms. If fully fleshed out, it would be a Zork or D&D type game. It demonstrates some basic programming tasks such as reading data into an array from a file, getting and responding to user input, looping, control structures, system calls and function definitions. I share it here as example code for others also learning Python and I welcome comments. The code is for Python 3.x, but the comments explain how to easily convert it for use in Python 2.x. It is far from perfect and is for learning purposes only – something to tinker with. It is based on concepts from Creating Adventure Games on Your Computer by Tim Hartnell, which used the BASIC programming language. You are welcome to take this code and use and modify for any purpose you like. The current version of this code will always be at this location: mazegame-current . In this directory you find the program and the data files it will ask for when the program is run.
My previous blog entry Learning Python provides resources for those wanting to learn Python, as does the Dev page from my main website.
I have picked up learning to program in Python again. Looking to add it to my trophy case along with BASIC, x86 Assembler, IBM BAL, Pascal, Modula-2, Forth and C. In the process I have found some great resources, aside from the official Python website to share. The first two sites are excellent on-line books about programming in Python. The last two sites teach programming skills generally using Python as the example programming language.
A Byte of Python
Dive Into Python
Learning to Program
How to Think Like a Computer Scientist
More resources can be found on my Web Development and Programming page.