The other day, I saw an interesting question on StackOverflow where the author asked if there was a way to serialize a Python dictionary into a human-readable format. The answer that was given was to use a package called jsonpickle, which will serialize complex Python objects to and from JSON. This article will give you a quick overview of how to use the project.
Wed 13 Aug 2014
Thu 7 Aug 2014
The other day, I came across an article about a fork of the pbs package called sh. These packages are wrappers for Python’s subprocess module. Basically sh allows you to import and use shell commands directly from Python. This article will go over a few examples to show you how to use this fun little library.
Note that at the time of writing, the sh package only supports Linux and Mac. If you need Windows support, then you should try the pbs project.
Tue 5 Aug 2014
The arrow project is an attempt to wrap Python’s time and datetime modules into a single API. It also claims to plug gaps in functionality in those modules, such as time spans, ISO-8601 and humanization. You can kind of think of arrow as a drop-in replacement for Python’s datetime and time modules, much like the requests project can be used instead of Python’s urllib. Arrow supports Python 2.6, 2.7 and 3.3 at the time of this writing.
Mon 21 Jul 2014
The Pony ORM project is another object relational mapper package for Python. They allow you to query a database using generators. They also have an online ER Diagram Editor that is supposed to help you create a model. They are also one of the only Python packages I’ve seen with a multi-licensing scheme where you can develop using a GNU license or purchase a license for non-open source work. See their website for additional details.
In this article, we will spend some time learning the basics of this package. (more…)
Thu 17 Jul 2014
I thought it would be fun to try out a few different Python object relational mappers (ORMs) besides SQLAlchemy. I recently stumbled across a project known as peewee. For this article, we will take the examples from my SQLAlchemy tutorial and port it to peewee to see how it stands up. The peewee project supports sqlite, postgres and MySQL out of the box, which isn’t as flexible as SQLAlchemy, but it’s not bad either. You can also use peewee with the Flask web framework, via a handy Flask-peewee plugin.
Anyway, let’s start playing around with this fun little library!
Mon 14 Jul 2014
Redirecting stdout seems to be a pretty common request on the wxPython users group, so I decided to see how easy it would be to do it with Tkinter. The typical use case for redirecting stdout or stderr is that you are calling some other process (like ping or tracert) and you want to catch what it’s doing to put it into your UI. Usually you can just use Python’s subprocess module and call its communicate() method to access the data. Then you can just print it to stdout and it will magically appear in your UI’s widget of choice.
Our finished user interface will look something like the following:
Let’s find out how to do this with Tkinter: (more…)
Fri 11 Jul 2014
I’ve been using wxPython for quite a while now and I see certain questions come up on a fairly frequent basis. One of the popular ones is how to ask the user for their credentials before loading up the rest of the application. There are several approaches to this, but I am going to focus on a simple solution as I believe this solution can be used as the basis for more complex solutions.
Basically what we want to happen is for the user to see a login dialog where they have to enter their username and password. If they enter it correctly, then the program will continue to load and they’ll see the main interface. You see this a lot on websites with a common use case being web email clients. Desktop applications don’t include this functionality as often, although you will see it for Stamps.com’s application and for law enforcement software. We will be creating a dialog that looks like this:
Tue 8 Jul 2014
Yesterday, Philip Guo made the claim that Python is now the most popular introductory teaching language at top U.S. universities on the Communications of the ACM blog. I came across this information via Planet Python’s redistribution of Vasudev Ram’s blog post on the subject.
If this is true, then I think this is really cool. Python is easy to learn and quite capable of most programming tasks. I’ve been using it for over 8 years now in all kinds of settings and Python has almost always come through for me. Anyway, check out the article and feel free to leave some feedback.
Mon 30 Jun 2014
Packt Publishing recently asked me if I would be interested in letting my readers know about a sale that they are doing right now. Most of the time, I avoid marketing to my readers, but Packt has a lot of Python ebooks for sale this week that I think you might find useful. Here is their press release (plus links to my reviews of the book, if applicable):
Packt Publishing celebrates 10 years with a special $10 offer
It has been 10 years since Packt Publishing embarked on its mission to deliver effective learning and information services to IT professionals. In that time, it has published over 2000 titles and helped projects become household names, awarding over $400,000 through its Open Source Project Royalty Scheme.
To celebrate this huge milestone, Packt is offering all of its eBooks and Videos at just $10 each – this promotion covers every title and customers can stock up on as many copies as they like until July 5th If you’ve already tried a Packt title in the past, you’ll know this is a great opportunity to explore what’s new and maintain your personal and professional development. If you’re new to Packt, then now is the time to try their extensive range – Within their 2000+ titles range, you’ll find the knowledge you really need , whether that’s specific learning on an emerging technology or the key skills to keep you ahead of the competition in more established tech fields.’
Some of the Python books that you can check out:
• Kivy Interactive Applications in Python (review)
• Tkinter GUI Application Development HOTSHOT (review)
• Instant Flask Web Development (review)
• web2py Application Development Cookbook (review)
• Numpy 1.5 Beginner’s Guide (review)
• MySQL for Python (review)
• Python Multimedia Application Beginner’s Guide (review)
• Python 3 Object Oriented Programming (review)
More information is available at: http://bit.ly/1mMzRAV
Thu 26 Jun 2014
Last week, DZone contacted me to ask if I would like to be featured in their “Dev of the Week” series. In other words, they wanted to do a short interview with me. The interview went live yesterday. You can read it here, if you like:
I don’t know why the link is on their java sub-domain, but needless to say, I talked about Python in almost all of my answers. I wouldn’t be posting a link to my interview on my blog if it didn’t have something to do with Python. Anyway, if you’d like to learn a little more about me, I thought you might find that interesting.