Celebrating the Release of "Automate the Boring Stuff with Python" with Discount Codes!

UPDATE: The promo period is over. These discount codes are no longer valid.

My latest book, "Automate the Boring Stuff with Python" is being released on Saturday, the 25th! This is a Python programming book for complete beginners who want to learn to code using practical projects. Automate the Boring Stuff with Python will be available online under a Creative Commons license as well, making it accessible to all. (I'm working furiously to finish formatting the HTML version right now! It will be posted to AutomateTheBoringStuff.com)

No Starch Press has the 30% discount code PYBUTLER that you can use to order the book off their site. You'll get an Early Access copy now (the first 12 chapters) and then the full book on the 25th the full ebook immediately.

In addition, I've also added 70% discount codes for my other books! These are the max discounts I can give (I don't receive royalties for these sales). Thanks so much to all my readers, I never imagined six years ago when I started writing that I would be here now. :D

Invent Your Own Computer Games with Python, 3rd Edition FAM5M2RM (Read online, download PDF or ebook)

Making Games with Python & Pygame 2A5GKQRE (Read online, download PDF or ebook)

Hacking Secret Ciphers with Python MRLEG3A7 (Read online, download PDF or ebook)

These discount codes will work for the next few days.

Read More

3rd Edition Released

Download the PDF

The 3rd edition of "Invent Your Own Computer Games with Python" is now available. The 3rd edition has been streamlined to provide the same content but in 50 fewer pages, making it an easier read. If you've already read the 2nd edition, there's no need to read the 3rd (unless you want to sharpen your Python skills). But for new readers, Invent with Python should be even easier to pick up.

Buy the 3rd Edition on Amazon

Read the 3rd Edition online for free

Read the 2nd Edition

The 3rd edition is also being used for the translations. Currently the Spanish translation is online (though incomplete). The German and Dutch versions are nearing completion as well.

Read More

Translate Your Python 3 Program with the gettext Module

You've written a Python 3 program and want to make it available in other languages. You could duplicate the entire code-base, then go painstakingly through each .py file and replace any text strings you find. But this would mean you have two separate copies of your code, which doubles your workload every time you need to make a change or fix a bug. And if you want your program in other languages, it gets even worse.

Fortunately, Python provides a solution with the gettext module.


Read More

Programming a Bot to Play the "Sushi Go Round" Flash Game

Update 2015/01/08: If you attended my NCSS class on making a bot for this game, you can download the sushi.zip file which has all the code in bot5.py. Feel free to send questions to me at [email protected] or tweet at me: @AlSweigart

This tutorial teaches how to write a bot that can automatically play the Flash game Sushi Go Round. The concepts in this tutorial can be applied to make bots that play other games as well. It's inspired by the How to Build a Python Bot That Can Play Web Games by Chris Kiehl. The primary improvement of this tutorial is it uses the cross-platform PyAutoGUI module to control the mouse and take screenshots. It is documented on its ReadTheDocs page.

Sushi Go Round is a resource management game similar to "Dine N Dash". You fill customer orders for different types of sushi and place them on the conveyor belt. Incoming customers may take other customer's sushi orders, forcing you to remake orders. Customers who wait too long to get orders end up leaving, costing you reputation. Angry customers can be placated with saki, but this bot does not make use of that feature. Ingredients will have to be ordered as they get low.

I've refined this bot so that it can successfully play all the way through the game, ending up with a score of about 38,000. The top scores are a little over 100,000, so there is still room for improvement with this bot. You can watch a YouTube video of the bot playing.

The source code and images for the bot can be downloaded here or viewed on GitHub.


Read More

Making a Text Adventure Game with the cmd and textwrap Python Modules

Text adventures are an old game genre where the entire world is textually described as a series of rooms. Play involves entering simple text commands such as "move north" or "eat pie". Each room in the game world has its own text description, items on the ground, and exits to adjacent rooms. "Room" is a general name for a single area in the game world: a room can be a large open canyon or the inside of a wardrobe. Multi-user text adventures, called MUDs or Multi-User Dungeons, were the precursor to modern MMORPGs. You can still play MUDs today by finding them on The Mud Connector.

Screenshot of an old text adventure game.

Text adventures are easyto make because they don't require graphics. This tutorial uses two Python modules, cmd and textwrap and makes minimal use of object-oriented programming, but you don't have to know OOP concepts to follow. (But in general, text adventures would do very well with an object-oriented approach.) This tutorial is for beginner Python 3 programmers.

The code for Text Adventure Demo is available on GitHub.


Read More