Python for the Oracle DBA – Easy to use

In my earlier post I said that Python is easy to use. I want to fill in some details in this post. I have two main points:

  1. Python is not easy to learn
  2. Python is easy to use after you learn it

My experience supports these points. I don’t really have time to research what other people say and somehow prove these points with scientific evidence. But, I do have my own recent experience with the language and I have thought about what I wanted to say about it to other people.

I had to work pretty hard to learn Python. I’m a reasonably technical person with experience programming in a number of languages. I mean, I have a CS degree from Harvard and I’ve been working with databases for over 20 years. But, when I started working through the Python Tutorial it did not come very easily. Python’s documentation on docs.python.org is very good but the tutorial didn’t work that well for me. Maybe it was too fast for someone who was new to the language. I thought that their explanation of list slices was hard to follow. Also, the range function in for loops seemed weird compared to other languages. When they started talking about list comprehensions and lambda expressions it was too much. I think the tutorial just covers too much ground too quickly. I have not seen a need for a lot of the features that are in the tutorial anyway. It probably makes sense to learn the language some other way. I really learned Python by taking two edX classes. The edX classes included programming assignments and a slower pace than the tutorial. There are even easier classes than the ones I took so probably someone who is new to Python should find a class that is at their pace and not bang their head against the wall trying to work through the tutorial.

When I say that Python is easy for an Oracle DBA to use I think I mean that once you learn the language it is easy to keep using it. I think that the built-in list and dictionary data structures are the strongest features of Python. It takes some effort to learn the syntax and what it means but once you know it they are great building blocks for your Python scripts. If you forget some detail the documentation is always there. Just Google Python list or Python dictionary. You will find most of the answers on Python.org’s documentation site and Stack Overflow. But, Google brings up all kinds of helpful information. I think the other thing that makes Python easy to use is its dynamic typing. You don’t have to declare a variable’s type. Just use the variable. It is nice for quick and dirty scripts. Just put a number or a string or a list in a variable and then use it. The other nice feature is that Python requires indentation. If you have an if statement or loop you have to indent the statements inside the if or loop. The style guide recommends 4 spaces. This is great for hacking together simple scripts. Python tells you right away if your spaces are off so you can make sure that you really have the things where you want them. Also, you do not have to use the more complicated features. I’ve used a bit of the object-oriented features but not much. I’ve never used a list comprehension or lambda expression. I have just used plan old ifs, loops, and functions and done everything I needed.

There is a lot more I can say about this and a lot more examples that I could give but the key point is that in my opinion and my experience Python is an easy language to come back to after you have been away from it for a while. It took work for me to learn the language at first, but once I had done so it was pretty easy to keep coming back to it. I think this is true because you can do so much with the main easy to use features of the language and because of the high quality documentation and other resources available.

Bobby

P.S. I took these two MIT edX classes:

MITx – 6.00.1x Introduction to Computer Science and Programming Using Python

MITx – 6.00.2x Introduction to Computational Thinking and Data Science

They included some computer science and a little statistics but you also learned Python and used it to write programs. These classes were too hard for people who have never written a program before but someone with programming experience would find them easier. They were easy for me and I was a CTA or course teaching assistant for each class and helped answer questions. But they were challenging enough that I learned Python.

P.P.S. A few weeks back we had a corporate event sort of like a hack-a-thon. I got to play with a Google database product that I had never seen before. A coworker uploaded some data that he had collected on his Raspberry Pi into the Google database and I wrote a quick and dirty Python script to pull in the data and graph it. I hacked the database code together from Google’s example code and wrote the plotting code based on other scripts that I have written.

Here is the output:

This is an example of being able to quickly build a useful script using Python.

About Bobby

I live in Chandler, Arizona with my wife and three daughters. I work for US Foods, the second largest food distribution company in the United States. I have worked in the Information Technology field since 1989. I have a passion for Oracle database performance tuning because I enjoy challenging technical problems that require an understanding of computer science. I enjoy communicating with people about my work.
This entry was posted in Uncategorized. Bookmark the permalink.

9 Responses to Python for the Oracle DBA – Easy to use

  1. Pingback: Python for the Oracle DBA – Outline/Intro | Bobby Durrett's DBA Blog

  2. jimroll says:

    Hi, Bobby! Which course from edX have you learnt?

    • Bobby says:

      I took these two MIT edX classes:

      MITx – 6.00.1x Introduction to Computer Science and Programming Using Python

      MITx – 6.00.2x Introduction to Computational Thinking and Data Science

      They included some computer science and a little statistics but you also learned Python and used it to write programs. People who have never written a program before found these classes to be too hard but someone with prior experience would find them easier. They were easy for me and I was a CTA or course teaching assistant for each class and helped answer questions. But they were challenging enough that I learned Python.

      Bobby

      • jimroll says:

        Thanks for your reply!
        At the moment I signed up for the course Introduction to Python for Data Science by MS, which starts on October, 1.
        It is not clear for me, will the lessons have specific time or i can listen the course later, as in Uwe Hesse blog posts.
        Failed to find the details…

        • Bobby says:

          You can do the lessons any time you want but there are deadlines on when you have to finish. There is an online forum where you can discuss the class with others. The Python for data science class in the second in the series so you might want to do the other class first. I’m not sure when the other class starts up again. They have these archived classes that you can do any time but I’m not sure if you have the same level of participation in the forum discussions.

          • jimroll says:

            Ok, thanks!
            Not sure, that i have a questions for forum now. I’ve found DemoX course, reading and learning edX now 🙂

            Big thanks for your post about Python. My company uses it in some projects, but only one guy use it. I, as DBA, inspired by your example and want to learn it too. Bash is not powerful tool for scripting outside Oracle 🙂

          • Bobby says:

            I hope you enjoy the class. 🙂

  3. Karl Kranich says:

    This is encouraging, since I’ve often thought that tutorials go too deep too quickly. I’ll probably look into the edX classes. Thanks!

    • Bobby says:

      Karl,

      The two edX classes that I took take some time to do but I thought they were fun. You should have no trouble with them. Some people take the classes with no computer background at all and they get overwhelmed, but of course that isn’t your situation.

      Bobby

Leave a Reply