Every once in a while, I run into a situation where I need dummy data to test my code against. If you need to do tests on a new database or table, you will run into the need for dummy data often. I recently came across an interesting package called Faker. Faker’s sole purpose is to create semi-random fake data. Faker can create fake names, addresses, browser user agents, domains, paragraphs and much more. We will spend a few moments in this article demonstrating some of Faker’s capabilities. (more…)

Recently I ran into an issue where an application that calls Python would insert int into Python’s namespace, which overwrites Python’s built-in int function. Since I have to use the tool and I needed to use Python’s int function, I needed a way around this annoyance.

Fortunately, this is fairly easy to fix. All you need to do is import int from __builtin__ and rename it so you don’t overwrite the inserted version:

from __builtins__ import int as py_int

This gives you access to Python’s int function again, although it is now called py_int. You can name it whatever you like as long as you don’t name it int.

The most common circumstance where one shadows builtins or other variables is when the developer imports everything from a package or module:

from something import *

When you do an import like the one above, you don’t always know what all you have imported and you may end up writing your own variable or function that shadows one that you’ve imported. That is the main reason that importing everything from a package or module is so strongly discouraged.

Anyway, I hope you found this little tip helpful. In Python 3, the core developers added a builtins module basically for this very purpose.

My first book, Python 101 has been published today. You can buy it directly from my blog which will get you a PDF, EPUB and MOBI version of the book. You can also purchase a softcover edition of the book via Lulu. Finally, I have published the eBook to Amazon.

If you happen to run a Python or technology blog and would be interested in reviewing my book, Python 101, please feel free to contact me with your blog’s information. I am looking for a few good bloggers to review the book.

mousecovertitlejpg_sm2

Order Now

Here’s some more information about the book:

Part One

The first part is the beginner section. In it you will learn all the basics of Python. From Python types (strings, lists, dictionaries) to conditional statements to loops. You will also learn about comprehensions, functions and classes and everything in between! Note: This section has been completed and is in the editing phase.

Part Two

This section will be a curated tour of the Python Standard Library. The intent isn’t to cover everything in it, but instead it is to show the reader that you can do a lot with Python right out of the box. We’ll be covering the modules I find the most useful in day-to-day programming tasks, such as os, sys, logging, threads, and more.

Part Three

This section covers mostly intermediate level material. Here are the topics covered:

  • lambda
  • decorators
  • properties
  • debugging
  • testing
  • profiling

Part Four

Now things get really interesting! In part three, we will be learning how to install 3rd party libraries (i.e. packages) from the Python Package Index and other locations. We will cover easy_install and pip. This section will also be a series of tutorials where you will learn how to use the packages you download. For example, you will learn how to download a file, parse XML, use an Object Relational Mapper to work with a database, etc.

Part Five

The last section of the book will cover how to share your code with your friends and the world! You will learn how to package it up and share it on the Python Package Index (i.e. how to create an egg or wheel). You will also learn how to create executables using py2exe, bb_freeze, cx_freeze and PyInstaller. Finally you will learn how to create an installer using Inno Setup.

Writing Style

This book will be written using my original blogging style. This means that the chapters will be shorter than your usual programming textbook. Most chapters will most likely be less than 10 pages! The idea here is to get the reader up to speed on the subject, not to beat them over the head with it.
Who should read this book?

This book is for beginners, but I believe people with intermediate skills will also find its contents valuable.

IMAG0752

Python 101, the book I am authoring is nearly finished. I had a couple of “proof” copies produced by Lulu to verify things were laying out correctly and to help me find mistakes. Seeing it in print is pretty cool. It also made some oversights pretty obvious, although they’re all cosmetic in nature.

Anyway, right now I am just going through the book and doing some final edits. I also have an appendix to add and I am currently waiting for two more illustrations to be finished. The book is still scheduled to launch in June, 2014. You can actually pre-order the ebook now. I will add a link to the softcover when it’s ready for purchase, probably sometime during the first week of June.

Here’s a fun sneak peak of one of the next pieces of art:

mouselibraryink_sm

This contest is over!

masteringPythonOOP

Packt Publishing has partnered with my blog to give away 2 copies of their ebook version of Mastering Object-oriented Python by Steven Lott. You can read my full book review here, but frankly, I thought it was one of best advanced Python books I’ve read in a long time. It’s also based around Python 3, although most of the concepts will work with Python 2.

How You Can Win

To win your copy of this book, all you need to do is come up with a comment below highlighting the reason “why you would like to win this book”.

Duration of the contest & selection of winners

The contest is valid for 2 weeks, and is open to everyone. Winners will be selected on the basis of their comment posted. The contest will close on 05/26/2014 at 1 p.m. CST.

Packt Publishing asked me to be a technical reviewer for one of their latest Python books, Mastering Object-Oriented Python by Steven Lott. This book is a sequel of sorts to their 2010 release, Python 3 Object Oriented Programming by Dusty Phillips, which I reviewed here.

Note: This book is explicitly for Python 3 developers and does NOT talk about Python 2 much at all.


Quick Review

  • Why I picked it up: I was asked by the publisher to be a part of editing the book, however this is just the sort of book I like to read
  • Why I finished it: It’s quite well written and you learn a lot about how the internals of classes work
  • I’d give it to: An intermediate Python programmer who wants to learn new things

(more…)

Kivy is a neat package that allows Python developers to create user interfaces on mobile devices. You can also deploy the applications to desktops too. This is the second book I’ve seen put out on the subject. The first book, Kivy – Interactive Applications in Python by Roberto Ulloa came out last year from Packt Publishing. This year, we have Dusty Phillips’ work, Creating Apps in Kivy from O’Reilly. I will be reviewing the PDF version of the book.


Quick Review

  • Why I picked it up:I picked this book up because I like the author’s previous work, Python 3 Object Oriented Programming
  • Why I finished it: The book is pretty short and it’s interesting
  • I’d give it to: Someone who already knows Python

(more…)

Last month we looked at how to create Microsoft Excel (i.e. *.xls) files using the xlwt package. Today we will be looking at how we can read an *.xls/*.xlsx file using a package called xlrd. The xlrd package can be run on Linux and Mac as well as Windows. This is great when you need to process an Excel file on a Linux server.

We will start out by reading the first Excel file we created in our previous article.

Let’s get started! (more…)

Reportlab recently released version 3.1 which now fully supports Python 3 and Python 2.7. They had actually released a Python 3 compatible version about a month or so ago, but this one sounds like they’ve worked the bugs out of that initial release as this version also supports their commercial customers. I find this exciting in that one of my favorite Python packages finally supports Python 3. I haven’t moved to Python 3 myself because I use so many packages that are only available for Python 2 (and also because I have yet to work for a place that uses Python 3). There aren’t really any awesome new features in Reportlab 3.1 as of yet, but you can read through their release notes and decide for yourself.

One cool new feature of Reportlab is that you can now install it with pip or easy_install. They have also introduced Python wheel packages as their primary installation type, although you can still download the source. See PyPI for the open source downloads.

Check it out and let me know what you think!

If you’re like me, you missed PyCon North America 2014 this year. It happened last weekend. While the main conference days are over, the code sprints are still running. Anyway, for those of you who missed PyCon, they have released a bunch of videos on pyvideo! Every year, they seem to get the videos out faster than the last. I think that’s pretty awesome myself. I’m looking forward to watching a few of these so I can see what I missed.

« Previous PageNext Page »

Google+